package com.dhcc.DRGsHosp.facade.impl;

import com.dhcc.DRGsHosp.application.DepartmentApplication;
import com.dhcc.DRGsHosp.application.MonthAnalysisReportApplication;
import com.dhcc.DRGsHosp.core.domain.Department;
import com.dhcc.DRGsHosp.facade.DrgsIndexCalFacade;
import com.dhcc.DRGsHosp.facade.MonthAnalysisReportFacade;
import com.dhcc.DRGsHosp.facade.dto.IndexCalDTO;
import com.dhcc.DRGsHosp.infra.util.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
  * @Description:简版新版分析报告导出-POI技术
  * @Author:ShaoZhiYuan
  * @Date:2017年2月14日 下午2:25:40 
  * @version :2.3.2
  * @copyright:DHC 2015-2016
 */

@Named("monthAnalysisReportFacadeImpl")
public class MonthAnalysisReportFacadeImpl implements MonthAnalysisReportFacade {

	@Autowired
	private  MonthAnalysisReportApplication monthAnalysisReportApplication;
	@Inject
	private DrgsIndexCalFacade drgsIndexCalFacade;
	@Inject
	private DepartmentApplication departmentApplication;
	

	//存放全部信息的map
	private Map<String,Object> params= new HashMap<String,Object>();
	//存放图片信息的map
	private Map<String,Object> allMap= new HashMap<String,Object>();
	
	private String picRootio;
	private String wordRootio;
	private String writeRootio;
	
	private String depCodeQuFen;
	private String reportType;
	private  long start ;
	private  long reportNo;
	
	private List<List<String>> hosptable1=new ArrayList<List<String>>(); //全院表格1信息  病例未入组原因分布表
	private List<List<String>> hosptable4=new ArrayList<List<String>>(); //全院表格4信息  DRG病组总权重分布图（总权重前10）
	private List<List<String>> hosptable5=new ArrayList<List<String>>(); //全院表格5信息  各科室本期DRG病组覆盖情况表
	private List<List<String>> hosptable6=new ArrayList<List<String>>(); //全院表格6信息  各风险组死亡病例前5的科室分布情况表
	private List<List<String>> hosptable7=new ArrayList<List<String>>(); //全院表格7信息   各级手术病例入组情况
	private List<List<String>> hosptable8=new ArrayList<List<String>>(); //全院表格8信息   频次发生最高前五名手术操作的科室分布
	private List<List<String>> hosptable9=new ArrayList<List<String>>(); //全院表格9信息   各级手术作为主要手术出现频次最高的五位手术列表
	private List<List<String>> hosptable10=new ArrayList<List<String>>(); //全院表格10信息  各科室日间手术病例数分布情况

	
	private List<List<String>>  hospattachedTable1 =new ArrayList<List<String>>(); //全院附表1
	private List<List<String>>  hospattachedTable2 =new ArrayList<List<String>>(); //全院附表2
	private List<List<String>>  hospattachedTable3 =new ArrayList<List<String>>(); //全院附表3
	private List<List<String>>  hospattachedTable4 =new ArrayList<List<String>>(); //全院附表4
	private List<List<String>>  hospattachedTable5 =new ArrayList<List<String>>(); //全院附表5
	private List<List<String>>  hospattachedTable6 =new ArrayList<List<String>>(); //全院附表6
	private List<List<String>>  hospattachedTable7 =new ArrayList<List<String>>(); //全院附表7
	private List<List<String>>  hospattachedTable8 =new ArrayList<List<String>>(); //全院附表8
	
	private List<List<String>> deptable3=new ArrayList<List<String>>(); //科室表格3信息
	private List<List<String>> deptable4=new ArrayList<List<String>>(); //科室表格4信息
	private List<List<String>> deptable5=new ArrayList<List<String>>(); //科室表格5信息
	private List<List<String>> deptable6=new ArrayList<List<String>>(); //科室表格6信息
	private List<List<String>> deptable7=new ArrayList<List<String>>(); //科室表格7信息
	private List<List<String>> deptable8=new ArrayList<List<String>>(); //科室表格8信息
	private List<List<String>> deptable9=new ArrayList<List<String>>(); //科室表格9信息
	
	private List<List<String>>  depattachedTable1 =new ArrayList<List<String>>(); //科室附表1
	private List<List<String>>  depattachedTable2 =new ArrayList<List<String>>(); //科室附表2
	private List<List<String>>  depattachedTable3 =new ArrayList<List<String>>(); //科室附表3
	private List<List<String>>  depattachedTable5 =new ArrayList<List<String>>(); //科室附表5

	/**
	 * 
	  * @Description: 获取当前系统中数据年份
	  * @return
	 */
	@Override
	public List<Map<String,Object>> getDataYear() {
		return monthAnalysisReportApplication.getDataYear();
	}

	/**
	 * 
	 * TODO 主方法
	 * 
	 * @author ShaoZhiYuan  
	 * @see com.dhcc.DRGsHosp.facade.AnalysisDRGsReportFacade#createDRGsReport(Map)
	 */
	@Override
	public Map<String, Object> findARDRGsReport(Map<String, Object> dto) {
        start = System.currentTimeMillis(); //生成文档开始时间
		allMap=new HashMap<>();
		Map<String,Object> paramMap= new HashMap<String,Object>();

		//存放分析报告图片位置地址
		picRootio=dto.get("picRoot")+"";
		//存放分析报告文档位置地址
		wordRootio=dto.get("wordRoot")+"";
		//存放生成的分析报告文档位置地址
		writeRootio=dto.get("writeRoot")+"";

		String dateFrom = dto.get("dateFrom")==null?"":dto.get("dateFrom").toString(); //开始日期
		String dateTo = dto.get("dateTo")==null?"":dto.get("dateTo").toString();        //终止日期
		dateFrom = DrgsIndex.formateDateFrom(dateFrom); //规范日期格式
		dateTo = DrgsIndex.formateDateTo(dateTo); //规范日期格式
		String dateFromY = DrgsIndex.getDateFromCc(dateFrom, "year");  //同期起始日期
		String dateToY = DrgsIndex.getDateFromCc(dateTo, "year");        //同期终止日期
		String dateFromYStart = dateFromY.substring(0, 4)+"-01-01";  //同期年初
		String dateToYEnd = dateToY.substring(0, 4)+"-12-31";        //同期年末
		String dateFromQ = DrgsIndex.getDateFromCc(dateFrom, "month"); //上期起始日期
		String dateToQ = DrgsIndex.getDateFromCc(dateTo, "month");       //上期终止日期
		String isMonth = dto.get("isMonth")==null?"month":dto.get("isMonth").toString();        //月度季度报告区分
		String dateQuater = dto.get("dateQuater")==null?"1":dto.get("dateQuater").toString();   //季度
		String dateQuaterQ = "";

		String hospCode = MonitorResultUtil.object2String(dto.get("hospCode")) ;
		if("month".equals(isMonth)){
			params.put("reportDate", dateTo.substring(0, 4)+"年"+dateTo.substring(5, 7).replaceAll("^(0+)", "")+"月");
			params.put("reportDateY", dateToY.substring(0, 4)+"年"+dateToY.substring(5, 7).replaceAll("^(0+)", "")+"月");
			params.put("reportDateQ", dateToQ.substring(0, 4)+"年"+dateToQ.substring(5, 7).replaceAll("^(0+)", "")+"月");
			params.put("reportType", "月度");
			params.put("reportSection", "近12个月");
		}else{
			dateFromQ = DrgsIndex.getDateFromCc(dateFromQ, "quarter"); //当前日期上个季度
			dateToQ = DrgsIndex.getDateFromCc(dateToQ, "quarter");       //当前日期上个季度
			if("1".equals(dateQuater)){
				dateQuaterQ="4";
				params.put("reportDateQ", dateToY.substring(0, 4)+"年"+dateQuaterQ+"季度");
			}else{
				dateQuaterQ=String.valueOf(Integer.valueOf(dateQuater)-1);
				params.put("reportDateQ", dateTo.substring(0, 4)+"年"+dateQuater+"季度");
			}
			params.put("reportDate", dateTo.substring(0, 4)+"年"+dateQuater+"季度");
			params.put("reportDateY", dateToY.substring(0, 4)+"年"+dateQuater+"季度");
			params.put("reportType", "季度");
			params.put("reportSection", "近4个季度");
		}
		dto.put("hospCode", hospCode) ; //院区编码
		dto.put("dateFrom", dateFrom) ;
		dto.put("dateTo", dateTo) ;
		dto.put("dateFromY", dateFromY) ;
		dto.put("dateToY", dateToY) ;
		dto.put("dateFromYStart", dateFromYStart) ;
		dto.put("dateToYEnd", dateToYEnd) ;
		dto.put("dateFromQ", dateFromQ) ;
		dto.put("dateToQ", dateToQ) ;
		
		// 根据科室条件判断监测类型
		if(StringUtils.hasLength(MonitorResultUtil.object2String(dto.get("depCode"))) ) {
			dto.put("monitorType", "dep") ;
        } else {
			dto.put("monitorType", "") ;
		}

		depCodeQuFen=dto.get("isInmedical")==null?"1":dto.get("isInmedical").toString()+""; //科室内外科区分
		reportType=dto.get("depCode")==null?"":dto.get("depCode").toString()+""; //全院与科室类型区分

		String isComplete=(dto.get("isComplete")==null?"":dto.get("isComplete").toString()); //是否进行数据完整性校验

		// 获取标杆定位id
		String stdId=drgsIndexCalFacade.getStdID(dto.get("dateFrom")+"",dto.get("dateTo")+"");
		//获取分组方案
        String groupScheme = drgsIndexCalFacade.getGroupScheme() ;
		dto.put("ver_region",groupScheme);
		dto.put("stdId",stdId);

   		//判断有没有数据
		int dataIsNull=monthAnalysisReportApplication.findARDataIsNull(dateFrom, dateTo,groupScheme,hospCode);
		if(dataIsNull!=0){
			//数据完整性校验
			List<Map<String,Object>> checkedList = monthAnalysisReportApplication.findARCheckedData(dateFrom, dateTo, hospCode);
			Map<String,Object> objch=checkedList.get(0);
			double operlevelRatio=objch.get("FIRST_JUDGE_VALUE")==null?0:Double.valueOf(objch.get("FIRST_JUDGE_VALUE").toString());
			double opercodeRatio=objch.get("TWO_JUDGE_VALUE")==null?0:Double.valueOf(objch.get("TWO_JUDGE_VALUE").toString());
			double opertypeRatio=objch.get("THREE_JUDGE_VALUE")==null?0:Double.valueOf(objch.get("THREE_JUDGE_VALUE").toString());
			double ditypeRatio=objch.get("FOUR_JUDGE_VALUE")==null?0:Double.valueOf(objch.get("FOUR_JUDGE_VALUE").toString());
			double dicodeRatio=objch.get("FIVE_JUDGE_VALUE")==null?0:Double.valueOf(objch.get("FIVE_JUDGE_VALUE").toString());
		    if (isComplete.trim().equals("1")&&(operlevelRatio <0.85 ||opercodeRatio<0.85|| opertypeRatio<0.85||ditypeRatio<0.85||dicodeRatio<0.85)) {
			  allMap.put("errorMessageData" ,"请检测您导入的数据中手术编码、手术级别、手术类型、诊断编码、诊断类型是否符合数据规范！");
			  return allMap;
			} else {
				//进行主要手术的手术操作判断
				String caseOperCount = monthAnalysisReportApplication.findHospCaseOperationCount(dto);
				if(Double.valueOf(caseOperCount).intValue()>=1) {
					loadARHospDataSection(dto, paramMap) ;
					//多线程处理
					ExecutorService indexPool = Executors.newFixedThreadPool(7);
					indexPool.execute(new AnalysisReportRunnableA(dto));
					indexPool.execute(new AnalysisReportRunnableB(dto));
					indexPool.execute(new AnalysisReportRunnableC(dto));
					indexPool.execute(new AnalysisReportRunnableD(dto));
					//关闭线程池
					indexPool.shutdown();
					//线程池里所有线程走完
					while(true){
			           if(indexPool.isTerminated()){
			                System.out.println("所有的子线程都结束了！");
			                break;
			            }
				    }
					return allMap;
				} else {
					 allMap.put("errorMessageData" ,"数据手术操作未区分判断,无法生成报告,请在系统中维护或手动维护");
					return allMap;
				}
			}
		}else{
			 allMap.put("errorMessageData" ,"您选择的时间段内无数据, 生成文档失败");
			 return allMap;
		}
	}

	//医院基础信息单独处理,方便计算做分母调用
	public void loadARHospDataSection(Map<String, Object> dto, Map<String, Object> paramMap){
		// 获取出院病历术，大于60.入组数， 入组率
		List<Map<String,Object>> hospBaseQuotaStOne = monthAnalysisReportApplication.findARSimpHospBaseQuota(dto);
		Map<String,Object> hospBaseQuotaStOneMap=hospBaseQuotaStOne.get(0);
		params.put("hospoutcasecnt", hospBaseQuotaStOneMap.get("ALLCNT") == null ? "0": Arith.dataFormat(hospBaseQuotaStOneMap.get("ALLCNT").toString(), "2"));// 出院病例数
		params.put("hospoutcasecnt_temp", hospBaseQuotaStOneMap.get("ALLCNT") == null ? "0": Integer.parseInt(hospBaseQuotaStOneMap.get("ALLCNT")+""));// 出院病例数 (未格式化)
		params.put("ingpcacnt",hospBaseQuotaStOneMap.get("INGROUP") == null ? "0" : Arith.dataFormat(hospBaseQuotaStOneMap.get("INGROUP").toString(), "2"));// 入组数
		params.put("ingroupcasecnt_temp",hospBaseQuotaStOneMap.get("INGROUP") == null ? "0" : hospBaseQuotaStOneMap.get("INGROUP").toString());// 入组数 (未格式化)
		params.put("oversixtycasecnt", hospBaseQuotaStOneMap.get("OVERSIXTY") == null ? "0" : Arith.dataFormat(hospBaseQuotaStOneMap.get("OVERSIXTY").toString(), "2"));// 大于60
		params.put("oversixtycasecnt_temp", hospBaseQuotaStOneMap.get("OVERSIXTY") == null ? "0" : hospBaseQuotaStOneMap.get("OVERSIXTY").toString());// 大于60 (未格式化)
		params.put("ingroupRatio", (hospBaseQuotaStOneMap.get("GROUPRATIO") == null ? 0 : hospBaseQuotaStOneMap.get("GROUPRATIO"))+"%");// 入组率
		params.put("notingrocasecnt", hospBaseQuotaStOneMap.get("NOTINGROUP") == null ? "0": Arith.dataFormat(hospBaseQuotaStOneMap.get("NOTINGROUP").toString(), "2"));// 未入组
		params.put("notingrocasecnt_temp", hospBaseQuotaStOneMap.get("NOTINGROUP") == null ? "0": hospBaseQuotaStOneMap.get("NOTINGROUP").toString().trim());// 未入组 (未格式化)
	}


    //加载第一个章节信息
	public void loadARFirstSection(Map<String, Object> dto){
		// 获取医院名称
	    String hospName=dto.get("hospName")==null?"--":dto.get("hospName").toString().trim();
	    if(hospName.endsWith("医院")){
			hospName=hospName.substring(0, hospName.length()-2);
		}
	    String depCode = MonitorResultUtil.object2String(dto.get("depCode")) ;
	    //院区编码
	    String hospCode=dto.get("hospCode")==null?"":dto.get("hospCode").toString().trim();
		String isMonth = dto.get("isMonth")==null?"month":dto.get("isMonth").toString();        //月度季度报告区分
	    if("".equals(depCode)){
	    	params.put("depName", "");
	    }else{
	    	Department depNameList = departmentApplication.findDepartmentByDepCode(depCode);
	    	String depName = depNameList.getDepName();
	    	params.put("depName", depName);
	    }
		params.put("hospName", hospName);

		//分析报告创建日期
		Calendar cal = Calendar.getInstance();// 使用日历类
		String year = cal.get(Calendar.YEAR) + "";// 得到年
		String month = (cal.get(Calendar.MONTH) + 1) + "";// 得到月，因为从0开始的，所以要加1
		params.put("createYear", year);
		params.put("createMonth", month);

		String hospLevel=dto.get("hospLevel")==null?"--":dto.get("hospLevel").toString().trim();  //医院级别
		String hospBuildYear=dto.get("hospBuildYear")==null?"--":dto.get("hospBuildYear").toString(); //创建年份
		String hospBedNum=dto.get("hospBedNum")==null?"--":Arith.dataFormat(dto.get("hospBedNum").toString(), "2");  //核定床位数
		String hospRealBedNum=dto.get("hospRealBedNum")==null?"--":Arith.dataFormat(dto.get("hospRealBedNum").toString(), "2");  //实际床位数
		String hospCaseNum=dto.get("hospCaseNum")==null?"--":Arith.dataFormat(dto.get("hospCaseNum").toString(), "2"); //年门急诊量
		String hospDocNum=dto.get("hospDocNum")==null?"--":Arith.dataFormat(dto.get("hospDocNum").toString(), "2");    //医师数量
		
		params.put("hospBuildYear", hospBuildYear);
		params.put("hospLevel", hospLevel);
		params.put("hospBedNum", hospBedNum);
		params.put("hospRealBedNum", hospRealBedNum);
		params.put("hospCaseNum", hospCaseNum);
		params.put("hospDocNum", hospDocNum);
		
		IndexCalDTO indexDto = new IndexCalDTO();
		indexDto.setDateFrom(dto.get("dateFrom")+"");
		indexDto.setDateTo(dto.get("dateTo")+"");
		indexDto.setHospCode(dto.get("hospCode")+"");
		indexDto.setMonitorType(MonitorResultUtil.object2String(dto.get("monitorType")));
		if(depCode!=null) {
			indexDto.setPardepCode(depCode);
		}
		List<Map<String, Object>> resultList = new ArrayList<>() ;
		String sql = "" ;

		//第一章节开始
		indexDto.setQuotaCode("TotalCaseCnt" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		String totalCaseCnt = "0.0";
		String totalCaseCntYoY = "0.0";
		String totalCaseCntQoQ = "0.0";
		resultList = drgsIndexCalFacade.indexCal(indexDto );
		if(resultList!=null && resultList.size()>0) {
			totalCaseCnt = MonitorResultUtil.object2String(resultList.get(0).get("QuotaValue"));
			totalCaseCntYoY = MonitorResultUtil.object2String(resultList.get(0).get("QuotaValuecc"));
		}
		params.put("1-1-totalCaseCnt", Arith.dataFormat(totalCaseCnt, "2"));
		params.put("1-1-totalCaseCntYoY", Arith.dataFormat(totalCaseCntYoY, "2"));
		params.put("1-1-depCaseCntRatio", Arith.dataFormat(100* MonitorResultUtil.calculator("/", params.get("1-1-totalCaseCnt"), params.get("hospoutcasecnt"))+"", "3"));
		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))) {
			indexDto.setCompareType("month");
		} else {
			indexDto.setCompareType("quarter");
		}
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		if(resultList!=null && resultList.size()>0) {
			totalCaseCntQoQ = MonitorResultUtil.object2String(resultList.get(0).get("QuotaValuecc"));
		}
		params.put("1-1-totalCaseCntQoQ", Arith.dataFormat(totalCaseCntQoQ, "2"));

		indexDto.setQuotaCode("InCaseRatio" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		String inCaseRatio = "0.0";
		String inCaseRatioYear = "0.0";
		String inCaseRatioMonth = "0.0";
		resultList = drgsIndexCalFacade.indexCal(indexDto );
		// 入组率 本期值和同期值
		if(resultList!=null && resultList.size()>0) {
			// 入组率本期值
			inCaseRatio = MonitorResultUtil.object2String(resultList.get(0).get("QuotaValue"));
			// 入组率同期值
			inCaseRatioYear = MonitorResultUtil.object2String(resultList.get(0).get("QuotaValuecc"));
		}

		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))) {
			indexDto.setCompareType("month");
		} else {
			indexDto.setCompareType("quarter");
		}
		resultList = drgsIndexCalFacade.indexCal(indexDto );
		List<Map<String,Object>> inCaseRatioList = new ArrayList<>() ;
		if(resultList!=null && resultList.size()>0 && "month".equals(isMonth)) {
			// 月度入组率上期值
			inCaseRatioMonth = MonitorResultUtil.object2String(resultList.get(0).get("QuotaValuecc"));
		}else if(resultList!=null && resultList.size()>0 && "quarter".equals(isMonth)){
			//季度入组率上期值
			inCaseRatioList= monthAnalysisReportApplication.quaterInCaseRatio(MonitorResultUtil.addMonth(dto.get("dateFrom")+"",-3), MonitorResultUtil.addMonth(dto.get("dateTo")+"",-3),depCode,hospCode);
			Map<String,Object> map = inCaseRatioList.get(0);
			inCaseRatioMonth = Arith.dataFormat(Arith.round(MonitorResultUtil.objectToDouble(map.get("INCASERATIO")), 2)+"", "1");
		}
		Double  inCaseRatioYoY = Math.abs(MonitorResultUtil.calculator("-", inCaseRatio, inCaseRatioYear,2)) ;
		Double  inCaseRatioQoQ = Math.abs(MonitorResultUtil.calculator("-", inCaseRatio, inCaseRatioMonth,2)) ;
		String  inCaseRatioMonthBeforeWord ="";
		String  inCaseRatioMonthAfterWord ="个百分点";
		if (Double.valueOf(inCaseRatio)>Double.valueOf(inCaseRatioMonth)){
			inCaseRatioMonthBeforeWord="上升";
			params.put("1-1-inCaseRatioQoQ", inCaseRatioMonthBeforeWord+inCaseRatioQoQ+inCaseRatioMonthAfterWord);
		}else if (Double.valueOf(inCaseRatio)<Double.valueOf(inCaseRatioMonth)) {
			inCaseRatioMonthBeforeWord="下降";
			params.put("1-1-inCaseRatioQoQ", inCaseRatioMonthBeforeWord+inCaseRatioQoQ+inCaseRatioMonthAfterWord);
		}else{
			inCaseRatioMonthBeforeWord="持平";
			inCaseRatioMonthAfterWord="";
			params.put("1-1-inCaseRatioQoQ", inCaseRatioMonthBeforeWord+inCaseRatioMonthAfterWord);
		}
		String  inCaseRatioYearBeforeWord ="";
		String  inCaseRatioYearAfterWord ="个百分点";
		if (Double.valueOf(inCaseRatio)>Double.valueOf(inCaseRatioYear)){
			inCaseRatioYearBeforeWord="上升";
			params.put("1-1-inCaseRatioYoY", inCaseRatioYearBeforeWord+inCaseRatioYoY+inCaseRatioYearAfterWord);
		}else if (Double.valueOf(inCaseRatio)<Double.valueOf(inCaseRatioYear)) {
			inCaseRatioYearBeforeWord="下降";
			params.put("1-1-inCaseRatioYoY", inCaseRatioYearBeforeWord+inCaseRatioYoY+inCaseRatioYearAfterWord);
		}else{
			inCaseRatioYearBeforeWord="持平";
			inCaseRatioYearAfterWord="";
			params.put("1-1-inCaseRatioYoY", inCaseRatioYearBeforeWord+inCaseRatioYearAfterWord);
		}
		params.put("1-1-inCaseRatio", Arith.dataFormat(inCaseRatio, "3"));
		params.put("1-1-inCaseRatioYear", Arith.dataFormat(inCaseRatioYear, "3"));
		params.put("1-1-inCaseRatioMonth", Arith.dataFormat(inCaseRatioMonth, "3"));

		sql = drgsIndexCalFacade.findSQLAnalysisreport("1-1_InCaseRatio","xinanyida_hosp_month",null,null);
		Map<String, Object> condition = new HashMap<>();
		condition.put("dateFrom", MonitorResultUtil.addMonth(dto.get("dateFrom")+"",-11)) ;
		condition.put("dateTo", dto.get("dateTo")+"") ;
        condition.put("ver_region",dto.get("ver_region"));
        condition.put("stdId",dto.get("stdId"));
        condition.put("hospCode",dto.get("hospCode")+"");
        
		if(StringUtils.hasLength(depCode.toString().trim())) {
			sql = sql.replaceAll("1=1", " dep.DEP_CODE is not null and 1=1 ");
			sql = sql.replaceAll("1=1", " dep.DEP_CODE=:depCode and  1=1  ");
			condition.put("depCode", depCode) ;
		}

		List<Map<String,Object>> diagram1List = new ArrayList<>() ;
		if("month".equals(isMonth)){
			diagram1List = monthAnalysisReportApplication.executeQueryForList(sql, condition ) ;
		}else{
			diagram1List = monthAnalysisReportApplication.quaterInCaseRatio(MonitorResultUtil.addMonth(dto.get("dateFrom")+"",-9),dto.get("dateTo")+"",depCode,hospCode);
		}
		for(Map<String,Object> map : diagram1List) {
			map.put("INCASERATIO", Arith.dataFormat(Arith.round(MonitorResultUtil.objectToDouble(map.get("INCASERATIO")), 2)+"", "1")) ;
		}
		allMap.put("diagram1", diagram1List) ;
		// 1.2	未入组原因分析
		List<Map<String, Object>> diagram2List= monthAnalysisReportApplication.findNotInGroupReasonList(dto);
		//未入组原因病例传到前台
		allMap.put("diagram2",diagram2List);
		List<String> notInGroupReasonListT =new ArrayList<String>();
		hosptable1=new ArrayList<List<String>>();
		int notInGroupReasonListN=1; //未入组原因个数
		int noInGroupNum=0;//未入组人数
		String notInGroupReasonListStr="--";
		if(diagram2List.size()<1){
			notInGroupReasonListT =new ArrayList<String>();
			notInGroupReasonListT.add("-");
			notInGroupReasonListT.add("-");
			notInGroupReasonListT.add("-");
			notInGroupReasonListT.add("-");
			notInGroupReasonListT.add("-");
			hosptable1.add(notInGroupReasonListT);
		}else{
			notInGroupReasonListStr="";
			for(Map<String, Object> obj:diagram2List){
				notInGroupReasonListT =new ArrayList<String>();
				notInGroupReasonListT.add(notInGroupReasonListN+"");
				notInGroupReasonListN++;
				noInGroupNum=noInGroupNum+Integer.valueOf(obj.get("CNT").toString());
				notInGroupReasonListT.add(obj.get("DECC")==null?"-":obj.get("DECC").toString().trim());
				notInGroupReasonListStr+=obj.get("DECC")==null?"-":obj.get("DECC").toString().trim()+"銆�";
				notInGroupReasonListT.add(Arith.dataFormat(obj.get("CNT")==null?"0":obj.get("CNT").toString().trim(),"2"));
				notInGroupReasonListT.add(Arith.dataFormat(imputedRatio(Double.valueOf(obj.get("CNT")==null?"0":obj.get("CNT").toString().trim()),
			    Double.valueOf(params.get("notingrocasecnt_temp")+""))+"","3"));
				notInGroupReasonListT.add(obj.get("RESUME")==null?"-":obj.get("RESUME").toString().trim());
				hosptable1.add(notInGroupReasonListT);
			}
		}
		params.put("1-2-noInGroupNum", noInGroupNum);
		if(notInGroupReasonListStr.length()>1){
			notInGroupReasonListStr=notInGroupReasonListStr.substring(0, notInGroupReasonListStr.length()-1);
		}
	}

	//加载第二章节信息
	public void loadARTwoSection(Map<String, Object> dto){
		IndexCalDTO indexDto = new IndexCalDTO();
		indexDto.setMonitorType(MonitorResultUtil.object2String(dto.get("monitorType")));
		String depCode = MonitorResultUtil.object2String(dto.get("depCode")) ;
		//院区编码
	    String hospCode=dto.get("hospCode")==null?"":dto.get("hospCode").toString().trim();
		if(StringUtils.hasLength(depCode)) {
			indexDto.setPardepCode(depCode);
		}
		List<Map<String, Object>> resultList = new ArrayList<>() ;
		String sql = "" ;
		Map<String,Object> condition = new HashMap<>();
		condition.put("dateFrom", dto.get("dateFrom"));
		condition.put("dateTo", dto.get("dateTo"));
        condition.put("ver_region",dto.get("ver_region"));
        condition.put("stdId",dto.get("stdId"));
        condition.put("hospCode",hospCode);
		if(StringUtils.hasLength(depCode)) {
			condition.put("depCode", depCode) ;
		}

//		2.1.	全院总体情况
		//去年全年出院病例数
		indexDto.setDateFrom(dto.get("dateFromYStart")+"");
		indexDto.setDateTo(dto.get("dateToYEnd")+"");
		indexDto.setHospCode(dto.get("hospCode")+"");
		indexDto.setQuotaCode("TotalCaseCnt" );
		indexDto.setIsGetCc("0");
		resultList = drgsIndexCalFacade.indexCal(indexDto );
		if(resultList!=null && resultList.size()>0) {
			params.put("2-1-1-TotalCaseCnt", MonitorResultUtil.dataFormat(resultList.get(0).get("QuotaValue"),"2"));
		}

//		2.1.1.	DRG指标情况
		indexDto.setDateFrom(dto.get("dateFrom")+"");
		indexDto.setDateTo(dto.get("dateTo")+"");
		indexDto.setQuotaCode("InCaseCnt,CMI,TotalWeight,DRGCount,TimeEff,FeeEff,AvgDays,AvgFee,Risk1Ratio" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		if(resultList!=null && resultList.size()>0) {
			params.put("2-1-1-InCaseCnt", MonitorResultUtil.dataFormat(resultList.get(0).get("InCaseCnt"),"2"));
			params.put("2-1-1-CMI", MonitorResultUtil.dataFormat(resultList.get(0).get("CMI"),"3"));
			params.put("2-1-1-TotalWeight", MonitorResultUtil.dataFormat(resultList.get(0).get("TotalWeight"),"3"));
			params.put("2-1-1-DRGCount", MonitorResultUtil.dataFormat(resultList.get(0).get("DRGCount"),"2"));
			params.put("2-1-1-TimeEff", MonitorResultUtil.dataFormat(resultList.get(0).get("TimeEff"),"3"));
			params.put("2-1-1-FeeEff", MonitorResultUtil.dataFormat(resultList.get(0).get("FeeEff"),"3"));
			params.put("2-1-1-AvgDays", MonitorResultUtil.dataFormat(resultList.get(0).get("AvgDays"),"3"));
			params.put("2-1-1-AvgFee", MonitorResultUtil.dataFormat(resultList.get(0).get("AvgFee"),"3"));
			params.put("2-1-1-Risk1Ratio", MonitorResultUtil.dataFormat(resultList.get(0).get("Risk1Ratio"),"3"));
			params.put("2-1-1-InCaseCntYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("InCaseCntcc"),"2"));
			params.put("2-1-1-CMIYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("CMIcc"),"3"));
			params.put("2-1-1-TotalWeightYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("TotalWeightcc"),"3"));
			params.put("2-1-1-DRGCountYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("DRGCountcc"),"2"));
			params.put("2-1-1-TimeEffYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("TimeEffcc"),"3"));
			params.put("2-1-1-FeeEffYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("FeeEffcc"),"3"));
			params.put("2-1-1-AvgDaysYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("AvgDayscc"),"3"));
			params.put("2-1-1-AvgFeeYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("AvgFeecc"),"3"));
			params.put("2-1-1-Risk1RatioYoY", MonitorResultUtil.dataFormat(resultList.get(0).get("Risk1Ratiocc"),"3"));
		}

		//本期DRG指标值
		Double InCaseCnt = Double.valueOf(resultList.get(0).get("InCaseCnt")+"");
		Double CMI = Double.valueOf(resultList.get(0).get("CMI")+"");
		Double TotalWeight = Double.valueOf(resultList.get(0).get("TotalWeight")+"");
		Double DRGCount = Double.valueOf(resultList.get(0).get("DRGCount")+"");
		Double TimeEff = Double.valueOf(resultList.get(0).get("TimeEff")+"");
		Double FeeEff = Double.valueOf(resultList.get(0).get("FeeEff")+"");
		Double Risk1Ratio = Double.valueOf(resultList.get(0).get("Risk1Ratio")+"");

		//同期DRG指标值
		Double InCaseCntCc = Double.valueOf(resultList.get(0).get("InCaseCntcc")+"");
		Double CMICc = Double.valueOf(resultList.get(0).get("CMIcc")+"");
		Double TotalWeightCc = Double.valueOf(resultList.get(0).get("TotalWeightcc")+"");
		Double DRGCountCc = Double.valueOf(resultList.get(0).get("DRGCountcc")+"");
		Double TimeEffCc = Double.valueOf(resultList.get(0).get("TimeEffcc")+"");
		Double FeeEffCc = Double.valueOf(resultList.get(0).get("FeeEffcc")+"");
		Double Risk1RatioCc = Double.valueOf(resultList.get(0).get("Risk1Ratiocc")+"");

		String hospQuatorBetter="";
		String hospQuatorWorse="";
		if(InCaseCnt>InCaseCntCc) {
			hospQuatorBetter+="入组病例数、";
		} else if(InCaseCnt<InCaseCntCc) {
			hospQuatorWorse+="入组病例数、";
		}
		if(CMI>CMICc) {
			hospQuatorBetter+="CMI、";
		} else if(CMI<CMICc) {
			hospQuatorWorse+="CMI、";
		}
		if(TotalWeight>TotalWeightCc) {
			hospQuatorBetter+="总权重、";
		} else if(TotalWeight<TotalWeightCc) {
			hospQuatorWorse+="总权重、";
		}
		if(DRGCount>DRGCountCc) {
			hospQuatorBetter+="DRGs组数、";
		} else if(DRGCount<DRGCountCc) {
			hospQuatorWorse+="DRGs组数、";
		}
		if(TimeEff<TimeEffCc) {
			hospQuatorBetter+="时间消耗指数、";
		} else if(TimeEff>TimeEffCc) {
			hospQuatorWorse+="时间消耗指数、";
		}
		if(FeeEff<FeeEffCc) {
			hospQuatorBetter+="费用消耗指数、";
		} else if(FeeEff>FeeEffCc) {
			hospQuatorWorse+="费用消耗指数、";
		}
		if(Risk1Ratio<Risk1RatioCc) {
			hospQuatorBetter+="低风险死亡人数、";
		} else if(Risk1Ratio>Risk1RatioCc) {
			hospQuatorWorse+="低风险死亡人数、";
		}
		if (hospQuatorBetter.lastIndexOf("、") > 0) {
			hospQuatorBetter= hospQuatorBetter.substring(0, hospQuatorBetter.lastIndexOf("、"))+"";
		}
		if (hospQuatorWorse.lastIndexOf("、") > 0) {
			hospQuatorWorse= hospQuatorWorse.substring(0, hospQuatorWorse.lastIndexOf("、"))+"";
		}
		if(hospQuatorBetter.length()>0){
			params.put("hospQuatorBetter", "，"+hospQuatorBetter+"指标变优");
		}else{
			params.put("hospQuatorBetter", "");
		}
		if(hospQuatorWorse.length()>0){
			params.put("hospQuatorWorse", "，"+hospQuatorWorse+"指标变差");
		}else{
			params.put("hospQuatorWorse", "");
		}

		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))) {
			indexDto.setCompareType("month");
		} else {
			indexDto.setCompareType("quarter");
		}
  		resultList = drgsIndexCalFacade.indexCal(indexDto);
  		if(resultList!=null && resultList.size()>0) {
  			params.put("2-1-1-InCaseCntQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("InCaseCntcc"),"2"));
  			params.put("2-1-1-CMIQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("CMIcc"),"3"));
			params.put("2-1-1-TotalWeightQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("TotalWeightcc"),"3"));
			params.put("2-1-1-DRGCountQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("DRGCountcc"),"2"));
			params.put("2-1-1-TimeEffQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("TimeEffcc"),"3"));
			params.put("2-1-1-FeeEffQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("FeeEffcc"),"3"));
			params.put("2-1-1-AvgDaysQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("AvgDayscc"),"3"));
			params.put("2-1-1-AvgFeeQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("AvgFeecc"),"3"));
			params.put("2-1-1-Risk1RatioQoQ", MonitorResultUtil.dataFormat(resultList.get(0).get("Risk1Ratiocc"),"3"));
  		}

		// 2.1.2	病例难度分布
  		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-1-2_CaseDifficultyDis","xinanyida_hosp_month",null,null);
		Map<String,Object> diagram3Map = new HashMap<>() ;
		List<Map<String,Object>> diagram3TempList = new ArrayList<>() ;
		diagram3TempList = monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		if(diagram3TempList.size()>0) {
			diagram3Map.put("thisOne", diagram3TempList.get(0)) ;
			Map<String,Object> mapThis = (Map<String, Object>) DrgsIndex.copyPropertiesObj(diagram3TempList.get(0)) ;
			mapThis.put("(0,0.5]", mapThis.remove("INTERVAL1")) ;
			mapThis.put("(0.5,0.8]", mapThis.remove("INTERVAL2")) ;
			mapThis.put("(0.8,1.2]", mapThis.remove("INTERVAL3")) ;
			mapThis.put("(1.2,2]", mapThis.remove("INTERVAL4")) ;
			mapThis.put("(2,5]", mapThis.remove("INTERVAL5")) ;
			mapThis.put("大于5", mapThis.remove("INTERVAL6")) ;
			// 这里将map.entrySet()转换成list
	        List<Entry<String,Object>> diagram3List = new ArrayList<Entry<String,Object>>(mapThis.entrySet());
	        // 通过比较器来实现排序
	        Collections.sort(diagram3List,new Comparator<Entry<String,Object>>() {
	            //升序排序
	            public int compare(Entry<String, Object> o1,
	                    Entry<String, Object> o2) {
	                return MonitorResultUtil.objectToDouble(o1.getValue()).compareTo(MonitorResultUtil.objectToDouble(o2.getValue()));
	            }
	        });
	        params.put("212-cntMax", diagram3List.get(diagram3List.size()-1).getKey()) ;
			params.put("212-cntMin", diagram3List.get(0).getKey()) ;
	    } else {
			params.put("212-cntMax", "-") ;
			params.put("212-cntMin", "-") ;
		}
		
		// 同期
		condition.put("dateFrom", dto.get("dateFromY"));
		condition.put("dateTo",dto.get("dateToY"));
		diagram3TempList = monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		if(diagram3TempList.size()>0) {
			diagram3Map.put("lastOne", diagram3TempList.get(0)) ;
		}
		
/*		// 上期
		condition.put("dateFrom",dto.get("dateFromQ"));
		condition.put("dateTo",dto.get("dateToQ"));
		diagram3TempList = monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		if(diagram3TempList.size()>0) {
			diagram3Map.put("上期", diagram3TempList.get(0)) ;
		}*/
		allMap.put("diagram3", diagram3Map) ;
	    
		/******************************************************************************************************/
		if(StringUtils.hasLength(depCode)) {
			// 科室
			loadARTwoSectionDep(dto,indexDto, condition) ;
		} else {
			// 全院
			loadARTwoSectionHosp(dto,indexDto, condition) ;
		}
		
	}
	
	private void loadARTwoSectionDep(Map<String, Object> dto, IndexCalDTO indexDto, Map<String, Object> condition){
		List<Map<String, Object>> resultList = new ArrayList<>() ;
		String sql = "" ;
		//		2.3.	病组覆盖情况
		condition.put("dateFrom", MonitorResultUtil.addMonth(dto.get("dateFrom")+"",-11)) ;
		condition.put("dateTo", dto.get("dateTo")+"") ;
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-4_effectiveProportion","xinanyida_dep_month",null,null);
		
		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))){
			sql = sql.replaceAll(":timeType", "to_char(ipinfo.p00290000,'yyyy-mm')");
		}else{
			condition.put("dateFrom",  MonitorResultUtil.addMonth(dto.get("dateFrom")+"",-9));
			sql = sql.replaceAll(":timeType", "to_char(ipinfo.p00290000,'yyyy')||'年第'||to_char(ipinfo.p00290000,'q')||'季度' ");
		}
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		
		if(resultList!=null&&resultList.size()>0) {
			params.put("23-drgcntInTheoryRatio", resultList.get(resultList.size()-1).get("DRGCNTINTHEORYRATIO")) ;
		} else {
			params.put("23-drgcntInTheoryRatio", "-") ;
		}
		allMap.put("diagram14", resultList) ;
//		
//		2.4.	病组效率分析
		indexDto.setMonitorType("drgs");
		indexDto.setQuotaCode("InCaseCnt,AvgDays,TimeEff,AvgFee,FeeEff");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<Object,Map<String,Object>> table3Map = listToMap(resultList,"ccode") ;
		
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-4_benchmarkingQuery","xinanyida_dep_month",null,null);
		condition.put("dateFrom", dto.get("dateFrom")) ;
		condition.put("dateTo", dto.get("dateTo")) ;
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		for(Map<String,Object> map : resultList) {
			if(table3Map.get(map.get("CCODE")) != null){
				table3Map.get(map.get("CCODE")).putAll(map);
			}
		}
		resultList = mapToList(table3Map);
		resultList = sortListMap(resultList, "InCaseCnt", "desc") ;
		double totalCnt_24 = 0 ;
		double overDays_24 = 0 ;
		double overFee_24 = 0 ;
		double overFeeAndDays_24 = 0 ;
		int num = 0 ;
		for(Map<String,Object> map: resultList) {
			if(num<10) {
				num++ ;
			} else {
				break ;
			}
			totalCnt_24+= MonitorResultUtil.objectToDouble(map.get("InCaseCnt")) ;
			double avgFee = MonitorResultUtil.objectToDouble(map.get("AvgFee")) ;
			double avgDay = MonitorResultUtil.objectToDouble(map.get("AvgDays")) ;
			double avgFeecc = MonitorResultUtil.objectToDouble(map.get("ASAVGFEE")) ;
			double avgDaycc = MonitorResultUtil.objectToDouble(map.get("ASAVGDAYS")) ;
			if(avgFee>avgFeecc) {
				overFee_24++ ;
			}
			if(avgDay>avgDaycc) {
				overDays_24++ ;
			}
			if(avgFee>avgFeecc && avgDay>avgDaycc) {
				overFeeAndDays_24++ ;
			}
		}
		
		if(resultList.size()>=10) {
			resultList = resultList.subList(0, 10) ;
		}
		
		params.put("24_totalCnt", (int)totalCnt_24);
		params.put("overFee_24", (int)overFee_24);
		params.put("overDays_24", (int)overDays_24);
		params.put("overFeeAndDays_24", (int)overFeeAndDays_24);
        params.put("24_totalCntRatio", MonitorResultUtil.calculator("/",totalCnt_24*100, params.get("1-1-totalCaseCnt"),"3"));
		String[] columns = {"ccode","ddesc","InCaseCnt(2)","AvgDays(3)","ASAVGDAYS(3)","TimeEff(3)","AvgFee(3)","ASAVGFEE(3)","FeeEff(3)"};
		deptable3=new ArrayList<List<String>>();
		
		deptable3 = listMapToListArray(resultList, columns); 
//		2.5.	医疗组效率分析
		indexDto.setMonitorType("clinic");
	    indexDto.setQuotaCode("InCaseCnt,CMI,AvgDays,AvgFee,TotalWeight,DRGCount,TimeEff,FeeEff");
		resultList = drgsIndexCalFacade.indexCal(indexDto);

		Map<Object,Map<String,Object>> table4Map = listToMap(resultList, "ccode") ;
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-5_excessCnt_TF","xinanyida_dep_month",null,null);
		condition.put("dateFrom", dto.get("dateFrom")) ;
		condition.put("dateTo", dto.get("dateTo")) ;
		
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		for(Map<String,Object> map : resultList) {
			if(table4Map.get(map.get("CCODE")) != null){
				table4Map.get(map.get("CCODE")).putAll(map);
			}
		}
		List<Map<String, Object>> table4List =   mapToList(table4Map) ;
		table4List = sortListMap(table4List, "TotalWeight", "desc") ;
		String[] columnsTable4 = {"ddesc","InCaseCnt","CMI(3)","TotalWeight(3)","DRGCount","AvgDays(3)","TimeEff(3)","AvgFee(3)","FeeEff(3)","SPECIFICDRGCODE"} ;
		deptable4=new ArrayList<List<String>>();
		deptable4 = listMapToListArray(table4List, columnsTable4) ;
		
        sql = drgsIndexCalFacade.findSQLAnalysisreport("2-5_excessDetail_TF","xinanyida_dep_month",null,null);
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		resultList = sortListMap(resultList, "CASECNT", "desc") ;
		String[] columnsTable5 = {"DDESC","DRG_CODE","DRG_DESC","CASECNT","AVGDAY(3)","ASAVGDAY(3)","AVGFEE(3)","ASAVGFEE(3)"} ;
		deptable5=new ArrayList<List<String>>();
		deptable5 = listMapToListArray(resultList, columnsTable5) ;
		
//		2.6.	死亡病例分布
		indexDto.setMonitorType("dep");
	    indexDto.setQuotaCode("DeadCaseCnt");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		double deathDep_26 = 0.0 ;
		if(resultList!=null && resultList.size()>0) {
			deathDep_26 = MonitorResultUtil.objectToDouble(resultList.get(0).get("QuotaValue"));
		}
		
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-6_distributionOfDeaths","xinanyida_dep_month",null,null);
		condition.put("dateFrom", dto.get("dateFrom"));
		condition.put("dateTo", dto.get("dateTo"));
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		double numRisk1Death = 0 ;
		double numDeath = 0 ;
		Set clinicSet=new HashSet();
		resultList = sortListMap(resultList, "CASECNT", "desc") ;
		for(Map<String,Object> map:resultList) {
			numDeath+= MonitorResultUtil.objectToDouble(map.get("CASECNT"));
			if("1".equals(MonitorResultUtil.object2String(map.get("RISKLEVEL")))) {
				clinicSet.add(map.get("CCODE"));
				numRisk1Death+= MonitorResultUtil.objectToDouble(map.get("CASECNT"));
			}
			map.put("deathRatio", Arith.dataFormat(100* MonitorResultUtil.calculator("/", map.get("CASECNT"), deathDep_26)+"", "3")) ;
		}
		params.put("26-deathCnt", (int)numDeath);
		params.put("26-risk1DeathCnt", (int)numRisk1Death);
		params.put("26-clinicCnt", clinicSet.size());
		String[] columnsTable6 = {"DRG_CODE","DRG_DESC","DDESC","DIC_DESC","CASECNT","deathRatio(3)"} ;
		deptable6=new ArrayList<List<String>>();
		deptable6 = listMapToListArray(resultList, columnsTable6) ;
		
	}
	
	/** 
	 * 	全院分析报告
	 *  loadARTwoSectionHosp.  
	 *  @Description：
	 *  @Author ChenHanlin
	 *  @param indexDto
	 *  @param condition 
	 *  @Date:2018年6月25日下午8:11:28
	 */
	private void loadARTwoSectionHosp(Map<String, Object> dto, IndexCalDTO indexDto, Map<String, Object> condition){
		List<Map<String, Object>> resultList = new ArrayList<>() ;
		String sql = "" ;
		int num = 0 ;
		//2.2.1	MDC专业病组覆盖率
		indexDto.setQuotaCode("DrgCountInMdc,DRGCount,DrgsCoverageRation");
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		indexDto.setMonitorType("mdc");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<Object,Map<String,Object>> diagram4Map = new HashMap<>() ;
		for(Map<String,Object> map : resultList) {
			Map<String,Object> tempMap = new HashMap<>() ;
			tempMap.put("code", map.get("ccode")) ;
			tempMap.put("desc", map.get("ddesc")) ;
			tempMap.put("DRGCount", map.get("DRGCount")) ;
			tempMap.put("DRGCountYoY", map.get("DRGCountcc")) ;
			tempMap.put("DrgsCoverageRation", map.get("DrgsCoverageRation")) ;
			tempMap.put("DrgCountInMdc", map.get("DrgCountInMdc")) ;
			diagram4Map.put(MonitorResultUtil.object2String(map.get("ccode")), tempMap) ;
		}
		
		List<Map<String,Object>> diagram4List = new ArrayList<>() ;
		diagram4List = mapToList(diagram4Map) ;
		diagram4List = sortListMap(diagram4List, "code", "ASC") ;
		allMap.put("diagram4", diagram4List) ;
		List<Map<String,Object>> diagram4ListOrd = sortListMap(diagram4List, "DrgsCoverageRation", "DESC") ;
		String mdcDrgsCoverageRation="";
		for(int i = 0;i<3;i++) {
			if(i<diagram4ListOrd.size()) {
				mdcDrgsCoverageRation+=diagram4ListOrd.get(i).get("code")+"-"+diagram4ListOrd.get(i).get("desc")+"("+diagram4ListOrd.get(i).get("DrgsCoverageRation")+"%)、";
				params.put("221-mdcDrgsCoverageRation"+i, diagram4ListOrd.get(i).get("code")+"-"+diagram4ListOrd.get(i).get("desc")+"("+diagram4ListOrd.get(i).get("DrgsCoverageRation")+"%)") ;
			} else {
				params.put("221-mdcDrgsCoverageRation"+i, "-") ;
			}
		}
		if (mdcDrgsCoverageRation.lastIndexOf("、") > 0) {
			mdcDrgsCoverageRation= mdcDrgsCoverageRation.substring(0, mdcDrgsCoverageRation.lastIndexOf("、"))+"";
		}
		params.put("mdcDrgsCoverageRation", mdcDrgsCoverageRation);
		
		// 2.2.2	MDC专业难度
		indexDto.setQuotaCode("CMI" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		indexDto.setMonitorType("mdc");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<Object,Map<String,Object>> diagram5Map = new HashMap<>() ;
		for(Map<String,Object> map : resultList) {
			Map<String,Object> tempMap = new HashMap<>() ;
			tempMap.put("code", map.get("ccode")) ;
			tempMap.put("desc", map.get("ddesc")) ;
			tempMap.put("CMI", map.get("QuotaValue")) ;
			tempMap.put("CMIYoY", map.get("QuotaValuecc")) ;
			diagram5Map.put(MonitorResultUtil.object2String(map.get("ccode")), tempMap) ;
		}
		
		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))) {
			indexDto.setCompareType("month");
		} else {
			indexDto.setCompareType("quarter");
		}
		resultList = drgsIndexCalFacade.indexCal(indexDto );
		for(Map<String,Object> map : resultList) {
			diagram5Map.get(map.get("ccode")).put("CMIQoQ", map.get("QuotaValuecc")) ;
		}
		List<Map<String,Object>> diagram5List = new ArrayList<>() ;
		diagram5List = mapToList(diagram5Map) ;
		diagram5List = sortListMap(diagram5List, "code", "ASC");
		allMap.put("diagram5", diagram5List) ;
		List<Map<String,Object>> diagram5ListOrd = sortListMap(diagram5List, "CMI", "DESC") ;
		String mdcCmi="";
		for(int i = 0;i<3;i++) {
			if(i<diagram5ListOrd.size()) {
				mdcCmi+=diagram5ListOrd.get(i).get("code")+"-"+diagram5ListOrd.get(i).get("desc")+"("+diagram5ListOrd.get(i).get("CMI")+")、";
				params.put("222-mdcCmi"+i, diagram5ListOrd.get(i).get("code")+"-"+diagram5ListOrd.get(i).get("desc")+"("+diagram5ListOrd.get(i).get("CMI")+")") ;
			} else {
				params.put("222-mdcCmi"+i, "-") ;
			}
		}
		if (mdcCmi.lastIndexOf("、") > 0) {
			mdcCmi= mdcCmi.substring(0, mdcCmi.lastIndexOf("、"))+"";
		}
		params.put("mdcCmi", mdcCmi) ;
		
		//权重排名前三DRG
		indexDto.setQuotaCode("CMI" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		indexDto.setMonitorType("drgs");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<Object,Map<String,Object>> diagram5DRGMap = new HashMap<>() ;
		for(Map<String,Object> map : resultList) {
			Map<String,Object> tempMap = new HashMap<>() ;
			tempMap.put("code", map.get("ccode")) ;
			tempMap.put("desc", map.get("ddesc")) ;
			tempMap.put("CMI", map.get("QuotaValue")) ;
			diagram5DRGMap.put(MonitorResultUtil.object2String(map.get("ccode")), tempMap) ;
		}
		
		List<Map<String,Object>> diagram5DRGList = new ArrayList<>() ;
		diagram5DRGList = mapToList(diagram5DRGMap) ;
		diagram5DRGList = sortListMap(diagram5DRGList, "code", "ASC");
		List<Map<String,Object>> diagram5ListDRGOrd = sortListMap(diagram5DRGList, "CMI", "DESC") ;
		String drgWeight="";
		for(int i = 0;i<3;i++) {
			if(i<diagram5ListDRGOrd.size()) {
				drgWeight+=diagram5ListDRGOrd.get(i).get("code")+"-"+diagram5ListDRGOrd.get(i).get("desc")+"("+diagram5ListDRGOrd.get(i).get("CMI")+")、";
				params.put("222-drgWeight"+i, diagram5ListDRGOrd.get(i).get("code")+"-"+diagram5ListDRGOrd.get(i).get("desc")+"("+diagram5ListDRGOrd.get(i).get("CMI")+")") ;
			} else {
				params.put("222-drgWeight"+i, "-") ;
			}
		}
		if (drgWeight.lastIndexOf("、") > 0) {
			drgWeight= drgWeight.substring(0, drgWeight.lastIndexOf("、"))+"";
		}
		params.put("drgWeight", drgWeight) ;
				
		// 2.2.3.	MDC专业总权重
		indexDto.setQuotaCode("TotalWeight" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		indexDto.setMonitorType("mdc");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<Object,Map<String,Object>> diagram6Map = new HashMap<>() ;
		for(Map<String,Object> map : resultList) {
			Map<String,Object> tempMap = new HashMap<>() ;
			tempMap.put("code", map.get("ccode")) ;
			tempMap.put("desc", map.get("ddesc")) ;
			tempMap.put("TotalWeight", map.get("QuotaValue")) ;
			tempMap.put("TotalWeightYoY", map.get("QuotaValuecc")) ;
			diagram6Map.put(MonitorResultUtil.object2String(map.get("ccode")), tempMap) ;
		}
		List<Map<String,Object>> diagram6List = new ArrayList<>() ;
		diagram6List = mapToList(diagram6Map) ;
		diagram6List = sortListMap(diagram6List, "code", "ASC") ;
		allMap.put("diagram6", diagram6List) ;
		List<Map<String,Object>> diagram6ListOrd = sortListMap(diagram6List, "TotalWeight", "DESC") ;
		String mdcTotalWeight="";
		for(int i = 0;i<3;i++) {
			if(i<diagram6ListOrd.size()) {
				mdcTotalWeight+=diagram6ListOrd.get(i).get("code")+"-"+diagram6ListOrd.get(i).get("desc")+"("+diagram6ListOrd.get(i).get("TotalWeight")+")、";
				params.put("223-mdcTotalWeight"+i, diagram6ListOrd.get(i).get("code")+"-"+diagram6ListOrd.get(i).get("desc")+"("+diagram6ListOrd.get(i).get("TotalWeight")+")") ;
			} else {
				params.put("223-mdcTotalWeight"+i, "-") ;
			}
		}
		if (mdcTotalWeight.lastIndexOf("、") > 0) {
			mdcTotalWeight= mdcTotalWeight.substring(0, mdcTotalWeight.lastIndexOf("、"))+"";
		}
		params.put("mdcTotalWeight", mdcTotalWeight) ;
		
		indexDto.setQuotaCode("TotalWeight,InCaseCnt" );
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		indexDto.setMonitorType("drgs");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<Object,Map<String,Object>> diagram7Map = new HashMap<>() ;
		for(Map<String,Object> map : resultList) {
			Map<String,Object> tempMap = new HashMap<>() ;
			tempMap.put("code", map.get("ccode")) ;
			tempMap.put("desc", map.get("ccode")+"-"+map.get("ddesc")) ;
			tempMap.put("TotalWeight", map.get("TotalWeight")) ;
			tempMap.put("TotalWeightYoY", map.get("TotalWeightcc")) ;
			tempMap.put("InCaseCnt", map.get("InCaseCnt")) ;
			diagram7Map.put(MonitorResultUtil.object2String(map.get("ccode")), tempMap) ;
		}
		List<Map<String,Object>> diagram7List = new ArrayList<>() ;
		diagram7List = mapToList(diagram7Map) ;
		List<Map<String,Object>> diagram7ListOrd = sortListMap(diagram7List, "TotalWeight", "DESC") ;
		List<Map<String,Object>> diagram7Listtop10 = new ArrayList<>() ;
		Map<Object,Map<String,Object>> diagram7Maptop10 = new HashMap<>() ;
		for (int i=0;i<10;i++){
			Map<String,Object> tempMaptop10 = new HashMap<>() ;
			tempMaptop10.put("code", diagram7ListOrd.get(i).get("code")) ;
			tempMaptop10.put("desc", diagram7ListOrd.get(i).get("desc")) ;
			tempMaptop10.put("TotalWeight", diagram7ListOrd.get(i).get("TotalWeight")) ;
			tempMaptop10.put("TotalWeightYoY", diagram7ListOrd.get(i).get("TotalWeightYoY")) ;
			tempMaptop10.put("InCaseCnt", diagram7ListOrd.get(i).get("InCaseCnt")) ;
			diagram7Maptop10.put(MonitorResultUtil.object2String(diagram7ListOrd.get(i).get("code")), tempMaptop10) ;
		}
		diagram7Listtop10 = mapToList(diagram7Maptop10) ;
		diagram7Listtop10 = sortListMap(diagram7Listtop10, "TotalWeight", "DESC") ;
		String[] quotas2_2_3 = {"desc","InCaseCnt(2)","TotalWeight","TotalWeightYoY"} ;
		hosptable4=new ArrayList<List<String>>();
		hosptable4 = listMapToListArray(diagram7Listtop10, quotas2_2_3);
		//allMap.put("diagram7", diagram7Listtop10) ;
		String drgTotalWeight="";
		for(int i = 0;i<3;i++) {
			if(i<diagram7ListOrd.size()) {
				drgTotalWeight+=diagram7ListOrd.get(i).get("desc")+"("+diagram7ListOrd.get(i).get("TotalWeight")+")、";
				params.put("223-drgTotalWeight"+i, diagram7ListOrd.get(i).get("desc")+"("+diagram7ListOrd.get(i).get("TotalWeight")+")") ;
			} else {
				params.put("223-drgTotalWeight"+i, "-") ;
			}
		}
		if (drgTotalWeight.lastIndexOf("、") > 0) {
			drgTotalWeight= drgTotalWeight.substring(0, drgTotalWeight.lastIndexOf("、"))+"";
		}
		params.put("drgTotalWeight", drgTotalWeight) ;
				
		// 2.2.4.	MDC专业效率
		indexDto.setQuotaCode("TimeEff,FeeEff");
		indexDto.setIsGetCc("1");
		indexDto.setCompareType("year");
		indexDto.setMonitorType("mdc");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<String, String> quotaMap = new HashMap<>() ;
		quotaMap.put("xDirection", "-1");
		quotaMap.put("yDirection", "-1");
		quotaMap.put("quotaCodeX", "TimeEff");
		quotaMap.put("quotaCodeY", "FeeEff");
		quotaMap.put("compareAttribute", "len");
		List<Map<String,Object>> diagram8AllList = orderScatterData(quotaMap, resultList,"cc") ;
		diagram8AllList = sortListMap(diagram8AllList, "len", "DESC") ;
		List<Map<String,Object>> diagram8List = new ArrayList<>() ;
		
		String mdcEffBetter="";
		for(int i = 0;i<5;i++) {
			if(i<diagram8AllList.size()&& MonitorResultUtil.objectToDouble(diagram8AllList.get(i).get("len"))>0) {
				diagram8List.add(diagram8AllList.get(i));
				mdcEffBetter+=diagram8AllList.get(i).get("ccode")+"-"+diagram8AllList.get(i).get("ddesc")+"("+diagram8AllList.get(i).get("TimeEff")+","+diagram8AllList.get(i).get("FeeEff")+")、";
				params.put("224-mdcEffBetter"+i, diagram8AllList.get(i).get("code")+"-"+diagram8AllList.get(i).get("desc")+"("+diagram8AllList.get(i).get("TimeEff")+","+diagram8AllList.get(i).get("FeeEff")+")") ;
				num++;
			} else {
				params.put("224-mdcEffBetter"+i, "") ;
			}
		}
		if (mdcEffBetter.lastIndexOf("、") > 0) {
			mdcEffBetter= mdcEffBetter.substring(0, mdcEffBetter.lastIndexOf("、"))+"";
		}
		allMap.put("diagram8", diagram8List) ;
		params.put("224-mdcEffBetterNum", num) ;
		params.put("mdcEffBetter", mdcEffBetter) ;
		
		Collections.reverse(diagram8AllList);
		List<Map<String,Object>> diagram9List = new ArrayList<>() ;
		num = 0 ;
		String mdcEffWorse="";
		for(int i = 0;i<5;i++) {
			if(i<diagram8AllList.size()&& MonitorResultUtil.objectToDouble(diagram8AllList.get(i).get("len"))<0) {
				diagram9List.add(diagram8AllList.get(i));
				mdcEffWorse+=diagram8AllList.get(i).get("ccode")+"-"+diagram8AllList.get(i).get("ddesc")+"("+diagram8AllList.get(i).get("TimeEff")+","+diagram8AllList.get(i).get("FeeEff")+")、";
				params.put("224-mdcEffWorse"+i, diagram8AllList.get(i).get("code")+"-"+diagram8AllList.get(i).get("desc")+"("+diagram8AllList.get(i).get("TimeEff")+","+diagram8AllList.get(i).get("FeeEff")+")") ;
				num++ ;
			} else {
				params.put("224-mdcEffWorse"+i, "") ;
			}
		}
		if (mdcEffWorse.lastIndexOf("、") > 0) {
			mdcEffWorse= mdcEffWorse.substring(0, mdcEffWorse.lastIndexOf("、"))+"";
		}
		params.put("mdcEffWorse", mdcEffWorse) ;
		
		allMap.put("diagram9", diagram9List) ;
		// 变差的个数
  		params.put("224-mdcEffWorseNum", num) ;
				
//		2.3.	科室分析
//		2.3.1	科室病组覆盖
		Map<Object,Map<String,Object>> table3Map = new HashMap<>() ;
		indexDto.setQuotaCode("DRGCount_t,DRGCount");
		indexDto.setIsGetCc("0");
		indexDto.setMonitorType("dep");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		for(Map<String,Object> map : resultList) {
			table3Map.put(MonitorResultUtil.object2String(map.get("ccode"), "-"), map) ;
		}
		
		condition = new HashMap<>();
		condition.put("dateFrom", dto.get("dateFrom")) ;
		condition.put("dateTo", dto.get("dateTo")) ;
		condition.put("hospCode", dto.get("hospCode")+"") ;
        condition.put("ver_region",dto.get("ver_region"));
        condition.put("stdId",dto.get("stdId"));
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-3-1_drgcntInTheory","xinanyida_hosp_month",null,null);
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		for(Map<String,Object> map : resultList) {
			if(table3Map.get(map.get("CCODE")) == null) {
				table3Map.put(map.get("CCODE"), map) ;
			} else {
				table3Map.get(map.get("CCODE")).put("drgcntInTheory", map.get("DRGCNTINTHEORY")) ;
			}
		}
		
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-3-1_drgcntOutActual","xinanyida_hosp_month",null,null);
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		for(Map<String,Object> map : resultList) {
			if(table3Map.get(map.get("CCODE")) == null) {
				table3Map.put(map.get("CCODE"), map) ;
			} else {
				table3Map.get(map.get("CCODE")).put("drgcntOutActual", map.get("DRGCNTOUTACTUAL")) ;

			}
		}
		
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-3-1_drgcntOutTheory","xinanyida_hosp_month",null,null);
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		for(Map<String,Object> map : resultList) {
			if(table3Map.get(map.get("CCODE")) == null) {
				table3Map.put(map.get("CCODE"), map) ;
			} else {
				table3Map.get(map.get("CCODE")).put("drgcntOutTheory", map.get("DRGCNTOUTTHEORY")) ;
			}
		}
						
		Iterator<Entry<Object, Map<String, Object>>>  it_2_3_1 = table3Map.entrySet().iterator() ;
		String[] quotas2_3_1 = {"num","ddesc","DRGCount_t(2)","DRGCount(2)","drgcntInTheory(2)",
				"effectiveProportion","drgcntOutActual","drgcntOutTheory"} ;
		// 计算病组有效占比
		while (it_2_3_1.hasNext()) {
			Entry<Object, Map<String, Object>> entry = it_2_3_1.next();  
			Map<String, Object> value = entry.getValue();  
			value.put("effectiveProportion", Arith.dataFormat(100* MonitorResultUtil.calculator("/", value.get("drgcntInTheory"), value.get("DRGCount_t"))+"","3"));
			if(value.get("drgcntOutActual") == null) {
				value.put("drgcntOutActual", 0) ;
			}
			if(value.get("drgcntOutTheory") == null) {
				value.put("drgcntOutTheory", 0) ;
			}
			if(value.get("drgcntInTheory") == null) {
				value.put("drgcntInTheory", 0) ;
			}
		} 
		num = 1 ;
		List<Map<String,Object>> table5Tmplist = mapToList(table3Map);
		List<Map<String,Object>> table5list = new ArrayList<>() ;
		table5Tmplist = sortListMap(table5Tmplist, "effectiveProportion", "desc");
		// 取病组有效占比最高的10个科室
		for(int i=0;i<table5Tmplist.size()&&i<10;i++) {
			table5Tmplist.get(i).put("num", num++) ;
			table5list.add(table5Tmplist.get(i)) ;
		}
		// List<Map<String,Object>>  -> List<List<String>>
		hosptable5=new ArrayList<List<String>>();
		hosptable5 = listMapToListArray(table5list, quotas2_3_1);

		indexDto.setQuotaCode("TotalCaseCnt" );
		indexDto.setIsGetCc("1");
		indexDto.setMonitorType("hosp");
		
		indexDto.setCompareType("year");
		resultList = drgsIndexCalFacade.indexCal(indexDto); 
		if(resultList!=null && resultList.size()>0) {
			params.put("hospoutcasecntYoY", resultList.get(0).get("QuotaValuecc"));
		}

		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))) {
			indexDto.setCompareType("month");
		} else {
			indexDto.setCompareType("quarter");
		}
		resultList = drgsIndexCalFacade.indexCal(indexDto); 
		if(resultList!=null && resultList.size()>0) {
			params.put("hospoutcasecntQoQ", resultList.get(0).get("QuotaValuecc"));
		}
		// 2.3.2	科室产出
		indexDto.setQuotaCode("TotalWeight,TotalCaseCnt,CMI" );
		indexDto.setIsGetCc("1");
		indexDto.setMonitorType("dep");
		indexDto.setCompareType("year");
		resultList = drgsIndexCalFacade.indexCal(indexDto); 
		Map<Object,Map<String,Object>> diagram10Map = new HashMap<>() ;
		for(Map<String,Object> map : resultList) {
			Map<String,Object> tempMap = new HashMap<>() ;
			tempMap.put("desc", MonitorResultUtil.object2String(map.get("ddesc"),"-")) ;
			tempMap.put("TotalWeight", map.get("TotalWeight")+"") ;
			tempMap.put("TotalWeightYoY", map.get("TotalWeightcc")+"") ;
			tempMap.put("caseRatio", Arith.dataFormat(100* MonitorResultUtil.calculator("/", map.get("TotalCaseCnt"),params.get("hospoutcasecnt"))+"", "3")) ;
			tempMap.put("caseRatioYoY", Arith.dataFormat(100* MonitorResultUtil.calculator("/", map.get("TotalCaseCntcc"),params.get("hospoutcasecntYoY"))+"", "3")) ;
			tempMap.put("CMI", MonitorResultUtil.object2String(map.get("CMI"))) ;
			tempMap.put("CMIYoY", MonitorResultUtil.object2String(map.get("CMIcc"))) ;
			diagram10Map.put(MonitorResultUtil.object2String(map.get("ccode")), tempMap) ;
		}
		
		if("month".equals(MonitorResultUtil.object2String(dto.get("isMonth")))) {
			indexDto.setCompareType("month");
		} else {
			indexDto.setCompareType("quarter");
		}
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		for(Map<String,Object> map : resultList) {
			diagram10Map.get(map.get("ccode")).put("caseRatioQoQ", Arith.dataFormat(100* MonitorResultUtil.calculator("/", map.get("TotalCaseCntcc"),params.get("hospoutcasecntQoQ"))+"", "3")) ;
			diagram10Map.get(map.get("ccode")).put("TotalWeightQoQ", MonitorResultUtil.object2String(map.get("TotalWeightcc"), "-")) ;
			diagram10Map.get(map.get("ccode")).put("CMIQoQ", MonitorResultUtil.object2String(map.get("CMIcc"),"-")) ;
		}
		List<Map<String,Object>> diagram10List = mapToList(diagram10Map) ;
		diagram10List = sortListMap(diagram10List, "TotalWeight", "desc") ;
		List<Map<String,Object>> diagram10ListTop10 = new ArrayList<>() ;
//		 取权重最高的10个科室
		for(int i=0;i<diagram10List.size()&&i<10;i++) {
			diagram10ListTop10.add(diagram10List.get(i)) ;
		}
		allMap.put("diagram10", diagram10ListTop10) ;
		
		num = 1 ;
		for(Map<String,Object> map:diagram10List) {
			map.put("num",num++) ;
		}
		// 格式转化 Map<String,Map<String,String>> -> List<List<String>>
		String[] quotas2_3_2 = {"num","desc","TotalWeight(3)","TotalWeightYoY(3)","TotalWeightQoQ(3)","caseRatio(3)","caseRatioYoY(3)","caseRatioQoQ(3)",
				"CMI(3)","CMIYoY(3)","CMIQoQ(3)"} ;
		hospattachedTable6=new ArrayList<List<String>>();
		hospattachedTable6 = listMapToListArray(diagram10List, quotas2_3_2) ;

		// 2.3.3	科室效率
		indexDto.setQuotaCode("TimeEff,FeeEff");
		indexDto.setIsGetCc("1");
		indexDto.setMonitorType("dep");
		indexDto.setCompareType("year");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		Map<String, String> quotaMapD11 = new HashMap<>() ;
		quotaMapD11.put("xDirection", "-1");
		quotaMapD11.put("yDirection", "-1");
		quotaMapD11.put("quotaCodeX", "TimeEff");
		quotaMapD11.put("quotaCodeY", "FeeEff");
		quotaMapD11.put("compareAttribute", "len");
		List<Map<String,Object>> diagram11AList = orderScatterData(quotaMapD11, resultList,"cc") ;
		diagram11AList = sortListMap(diagram11AList, "len", "DESC") ;
  		List<Map<String,Object>> diagram11List = new ArrayList<>() ;
  		num = 0 ;
  		String depEffBetter="";
  		for(int i = 0;i<5;i++) {
  			if(i<diagram11AList.size() && MonitorResultUtil.objectToDouble(diagram11AList.get(i).get("len"))>0) {
  				diagram11List.add(diagram11AList.get(i));
  				depEffBetter+=diagram11AList.get(i).get("ddesc")+"("+diagram11AList.get(i).get("TimeEff")+","+diagram11AList.get(i).get("FeeEff")+")、";
				params.put("233-depEffBetter"+i, diagram11AList.get(i).get("desc")+"("+diagram11AList.get(i).get("TimeEff")+","+diagram11AList.get(i).get("FeeEff")+")") ;
				num++ ;
  			} else {
  				params.put("233-depEffBetter"+i, "-") ;
  			}
  		}
  		if (depEffBetter.lastIndexOf("、") > 0) {
  			depEffBetter= depEffBetter.substring(0, depEffBetter.lastIndexOf("、"))+"";
		}
  		params.put("depEffBetter", depEffBetter) ;
  		allMap.put("diagram11", diagram11List) ;
//  		// 变好的个数
  		params.put("233-depEffBetterNum", num) ;
  		
  		Collections.reverse(diagram11AList);
  		List<Map<String,Object>> diagram12List = new ArrayList<>() ;
  		num = 0 ;
  		String depEffWorse="";
  		for(int i = 0;i<5;i++) {
  			if(i<diagram11AList.size() && MonitorResultUtil.objectToDouble(diagram11AList.get(i).get("len"))<0) {
  				diagram12List.add(diagram11AList.get(i));
  				depEffWorse+=diagram11AList.get(i).get("ddesc")+"("+diagram11AList.get(i).get("TimeEff")+","+diagram11AList.get(i).get("FeeEff")+")、";
				params.put("233-depEffWorse"+i, diagram11AList.get(i).get("desc")+"("+diagram11AList.get(i).get("TimeEff")+","+diagram11AList.get(i).get("FeeEff")+")") ;
				num++ ;
  			} else {
  				params.put("233-depEffWorse"+i, "-") ;
  			}
  		}
  		if (depEffWorse.lastIndexOf("、") > 0) {
  			depEffWorse= depEffWorse.substring(0, depEffWorse.lastIndexOf("、"))+"";
		}
  		allMap.put("diagram12", diagram12List) ;
  		params.put("233-depEffWorseNum", num) ;
  		params.put("depEffWorse", depEffWorse) ;
  		
  		// 2.3.4科室死亡病例
		indexDto.setQuotaCode("DeadCaseCnt,Risk1DeadCaseCnt");
		indexDto.setIsGetCc("0");
		indexDto.setMonitorType("hosp");
		resultList = drgsIndexCalFacade.indexCal(indexDto);
		String deadCaseCnt = "0";
		String risk1DeadCaseCnt = "0";
		if(resultList!=null && resultList.size()>0) {
			deadCaseCnt = MonitorResultUtil.object2String(resultList.get(0).get("DeadCaseCnt"))  ;
			risk1DeadCaseCnt = MonitorResultUtil.object2String(resultList.get(0).get("Risk1DeadCaseCnt"))  ;
		}
		params.put("234-deadCaseCnt", MonitorResultUtil.dataFormat(deadCaseCnt, "2"));
		params.put("234-risk1DeadCaseCnt", risk1DeadCaseCnt);
		sql = drgsIndexCalFacade.findSQLAnalysisreport("2-3-4_distributionOfDeaths","xinanyida_hosp_month",null,null);
		resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
		String[] columns = {"RISKLEVELDESC","RESULT"} ;
		hosptable6=new ArrayList<List<String>>();
		hosptable6 = listMapToListArray(resultList,columns) ;
	}
	
	//加载第三章节信息
	public void loadARThirdSection(Map<String, Object> dto){
		List<Map<String, Object>> resultList = new ArrayList<>() ;
		Map<String,Object> condition = new HashMap<>();
		condition.put("dateFrom", dto.get("dateFrom"));
		condition.put("dateTo", dto.get("dateTo"));
		condition.put("hospCode", dto.get("hospCode")==null?"":dto.get("hospCode")+""); //院区编码
		condition.put("ver_region", dto.get("ver_region"));
		condition.put("stdId", dto.get("stdId"));

		String sql = "" ;
		String depCode = MonitorResultUtil.object2String(dto.get("depCode")) ;
		if(StringUtils.hasLength(depCode)) {
			//科室
//			3.1.科室手术情况
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-1_operationHosp","xinanyida_hosp_month",null,null);		
			String isMonth = dto.get("isMonth")==null?"month":dto.get("isMonth").toString();        //月度季度报告区分
			if("month".equals(isMonth)){
				sql = sql.replaceAll("timeType", "to_char(ipinfo.p00290000,'yyyy-mm')");
			}else{
				condition.put("dateFrom",  MonitorResultUtil.addMonth(dto.get("dateFrom")+"",-9));
				sql = sql.replaceAll("timeType", "to_char(ipinfo.p00290000,'yyyy')||'年第'||to_char(ipinfo.p00290000,'q')||'季度' ");
			}
			//将科室信息加上
			condition.put("depCode", depCode);
			if(StringUtils.hasLength(depCode.toString().trim())) {
			sql = sql.replaceAll("1=1", " ipinfo.P00300001 is not null and ipinfo.P00300001=:depCode and 1=1 ");
			}
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			String[] columns = {"DDESC","TOTALCASECNT","OPECASECNT","OPECASECNTR(3)","FIRLEVEL","SECLEVEL","THIRLEVEL","FOURLEVEL","THREEANDFOUR","FOURLEVELR(3)"} ;
			deptable7=new ArrayList<List<String>>();
			deptable7 = listMapToListArray(resultList,columns) ;
			
			//3.2科室手术列表
			//科室手术条数查询
			condition.put("dateFrom",  dto.get("dateFrom"));
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2-1_depParagraph","xinanyida_dep_month",null,null);
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			if(resultList!=null&&resultList.size()>0) {
				Map<String,Object> resultMap = resultList.get(0) ;
				params.put("3-2_opeCnt", Arith.dataFormat(resultMap.get("OPECNT").toString(), "2")) ;
				params.put("3-2_top20Cnt", Arith.dataFormat(resultMap.get("TOP20CNT").toString(), "2")) ;
				params.put("3-2_top20CntR", Arith.dataFormat(resultMap.get("TOP20CNTR").toString(), "2")) ;
			}
			//科室级别顺序查询
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2-2_depParagraph","xinanyida_dep_month",null,null);
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			if(resultList!=null&&resultList.size()>0) {
				Map<String,Object> resultMap = resultList.get(0) ;
				params.put("3-2_MAX1Level", resultMap.get("MAX1")) ;
				params.put("3-2_MAX2Level", resultMap.get("MAX2")) ;
			}
			//表格8
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2_operationQKDep","xinanyida_dep_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			String[] aColumns = {"RK","OPECODE","OPEDESC","OPELEVELCODE","CNTOPE"} ;
			deptable8=new ArrayList<List<String>>();
			deptable8 = listMapToListArray(resultList,aColumns) ;
			
			// 表格 9 各级手术作为主要手术出现频次最高的五位手术列表
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2_mainOpeTop5","xinanyida_hosp_month",null,null);		
			//将科室信息加上
			if(StringUtils.hasLength(depCode.toString().trim())) {
				sql = sql.replaceAll("1=1", " ipinfo.P00300001 is not null and ipinfo.P00300001=:depCode and 1=1 ");
			}
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			String[] columnsT9 = {"RK","OPELEVEL","OPECODE","OPEDESC","CNTOPE","CNTOPER(3)"} ;
			deptable9=new ArrayList<List<String>>();
			deptable9 = listMapToListArray(resultList,columnsT9) ;
			
		} else {
			// 3.1.	全院手术情况
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-1_operationSummary","xinanyida_hosp_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			List<Map<String,Object>> diagram11List = new ArrayList<>() ;
			Map<String,Object> diagram10Map = new HashMap<>() ;
			if(resultList!=null&&resultList.size()>0) {
				Map<String,Object> resultMap = resultList.get(0) ;
				params.put("3-1_caseCnt", Arith.dataFormat(resultMap.get("TOTALCASECNT").toString(), "2")) ;
				params.put("3-1_opecaseCnt", Arith.dataFormat(resultMap.get("OPECASECNT").toString(), "2")) ;
				params.put("3-1_opecaseCntR", resultMap.get("OPECASECNTR")) ;
				
				diagram10Map.put("opecaseCntR", resultMap.get("OPECASECNTR")) ;
				diagram10Map.put("noOpecaseCntR", MonitorResultUtil.calculator("-", 100, resultMap.get("OPECASECNTR"))) ;
				
				Map<String,Object> map1 = new HashMap<String,Object>() ;
				map1.put("value", resultMap.get("FIRLEVELR")) ;
				map1.put("desc", "一级") ;
				map1.put("code", "FIRLEVELR") ;
				diagram11List.add(map1) ;
				Map<String,Object> map2 = new HashMap<String,Object>() ;
				map2.put("value", resultMap.get("SECLEVELR")) ;
				map2.put("desc", "二级") ;
				map2.put("code", "SECLEVELR") ;
				diagram11List.add(map2) ;
				Map<String,Object> map3 = new HashMap<String,Object>() ;
				map3.put("value", resultMap.get("THIRLEVELR")) ;
				map3.put("desc", "三级") ;
				map3.put("code", "THIRLEVELR") ;
				diagram11List.add(map3) ;
				Map<String,Object> map4 = new HashMap<String,Object>() ;
				map4.put("value", resultMap.get("FOURLEVELR")) ;
				map4.put("desc", "四级") ;
				map4.put("code", "FOURLEVELR") ;
				diagram11List.add(map4) ;
				Map<String,Object> map5 = new HashMap<String,Object>() ;
				map5.put("value", resultMap.get("OTHERLEVELR")) ;
				map5.put("desc", "其他") ;
				map5.put("code", "OTHERLEVELR") ;
				diagram11List.add(map5) ;
			}
			allMap.put("diagram1new", diagram10Map) ;
			allMap.put("diagram2new", diagram11List) ;
			diagram11List  = sortListMap(diagram11List, "value", "desc") ;
			params.put("3-1_maxR", diagram11List.get(0).get("desc")) ;
			params.put("3-1_maxRValue", diagram11List.get(0).get("value")) ;
			params.put("3-1_minR", diagram11List.get(diagram11List.size()-1).get("desc")) ;
			params.put("diagram11List", diagram11List) ;
			
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-1_operationInCase","xinanyida_hosp_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			for(Map<String,Object> map : resultList) {
				map.put("OPETATIONCNTR", MonitorResultUtil.calculator("/", MonitorResultUtil.objectToDouble(map.get("CASECNT"))*100 , resultList.get(0).get("CASECNT"),"3"));
			}
			String[] columnsT7 = {"DDESC","CASECNT","OPETATIONCNTR","INCASECNT","CMI","NOTINCASECNT"} ;
			hosptable7=new ArrayList<List<String>>();
			hosptable7 = listMapToListArray(resultList,columnsT7) ;
			
			// 3.2	重点手术分布
			//第一段 
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2_diagram1","xinanyida_hosp_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			if(resultList!=null&&resultList.size()>0) {
				Map<String,Object> resultMap = resultList.get(0) ;
				params.put("operationCount", Arith.dataFormat(resultMap.get("TOTALCNT").toString(), "2")) ;
				params.put("opeTop20Cnt", Arith.dataFormat(resultMap.get("TOP20CNT").toString(), "2")) ;
				params.put("opeTop20CntR", Arith.dataFormat(resultMap.get("TOP20CNTR").toString(), "3")) ;
			}
			// 表格 8 频次发生最高前五名手术操作的科室分布
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2_operationDepDis","xinanyida_hosp_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			
			int opeTop20Cnt = 0 ;
			double opeTop20CntR = 0.0 ;
			List<Map<String, Object>> resultListSum = new ArrayList<>() ;
			List<Map<String, Object>> resultListTop5 = new ArrayList<>() ;
			List<Map<String, Object>> resultListTop20 = new ArrayList<>() ;
			for(Map<String, Object> map :resultList) {
				if(MonitorResultUtil.objectToDouble(map.get("RK"))<=5) {
					resultListTop5.add(map) ;
					resultListTop20.add(map) ;
				} else if(MonitorResultUtil.objectToDouble(map.get("RK"))<=20) {
					resultListTop20.add(map) ;
				}
			}
			
			// 各级手术例数Map
			Map<String, Double> opeLevelCntMap = new HashMap<>() ;
			// 各级手术例数List
			List<Map<String, Object>> opeLevelCntList = new ArrayList<>() ;
			double d = 0.0 ;
			for(Map<String, Object> map:resultListTop20) {
				// 各级手术例数
				opeLevelCntMap.put(MonitorResultUtil.object2String(map.get("OPELEVELDESC")), MonitorResultUtil.calculator("+", map.get("CNTINDEP"), opeLevelCntMap.get(map.get("OPELEVELDESC"))));
				// 总手术例数
				opeTop20Cnt+= MonitorResultUtil.objectToDouble(map.get("CNTINDEP"));
			}
			opeTop20CntR = MonitorResultUtil.calculator("/", opeTop20Cnt*100, params.get("3-1_opecaseCnt")) ;
			// Map->List
			Iterator<Entry<String, Double>> it = opeLevelCntMap.entrySet().iterator();
			while (it.hasNext()) {
				Map<String,Object> map = new HashMap<>() ;
				Entry<String, Double> entry = it.next() ;
				map.put("ddesc", entry.getKey()) ;
				map.put("value", entry.getValue()) ;
				opeLevelCntList.add(map) ;
			}
			opeLevelCntList = sortListMap(opeLevelCntList, "value", "desc") ;
			if(opeLevelCntList.size()>0) {
				params.put("opeLevelCntMax1", MonitorResultUtil.object2String(opeLevelCntList.get(0).get("ddesc"))) ;
			}
			if(opeLevelCntList.size()>1) {
				params.put("opeLevelCntMax2", MonitorResultUtil.object2String(opeLevelCntList.get(1).get("ddesc"))) ;
			}
			
			int cntindep = 0 ;
			double cntindepR = 0.0 ;
			Map<String,Object> mapTemp = new HashMap<>() ;
			int num = 0 ;
			String rankTop5Dpes = "" ;
			Set<String> rankTop5DepSet = new TreeSet<>();
			for(Map<String,Object> map : resultListTop5) {
				// 如果排名大于3,则对数据进行合并
				if(MonitorResultUtil.objectToDouble(map.get("RKDEP"))<=3) {
					rankTop5DepSet.add(MonitorResultUtil.object2String(map.get("DEP_NAME")));
					if(cntindep>0) {
						mapTemp.put("CNTINDEPR", Arith.round(MonitorResultUtil.objectToDouble(mapTemp.get("CNTINDEPR")), 2));
				    	resultListSum.add(mapTemp);
				    	num++;
				    	// 清零
				    	cntindep = 0 ;
						cntindepR = 0.0 ;
				    } 
					resultListSum.add(num,map) ;
					num++;
				} else if(MonitorResultUtil.objectToDouble(map.get("RKDEP"))>3){
					mapTemp = new HashMap<>() ;
			    	cntindep += MonitorResultUtil.objectToDouble(map.get("CNTINDEP")) ;
			    	cntindepR += MonitorResultUtil.objectToDouble(map.get("CNTINDEPR")) ;
			    	mapTemp.putAll(map);
			    	mapTemp.put("OPELEVELCODE", "--");
			    	mapTemp.put("DEP_NAME", "其他");
			    	mapTemp.put("CNTINDEP", cntindep);
			    	mapTemp.put("CNTINDEPR", cntindepR);
			    	mapTemp.put("RKDEP", "4");
			    } 
			}
			for (String value : rankTop5DepSet) {
				rankTop5Dpes+=(value+"、") ;
				
			}    
			if(rankTop5Dpes.length()>0) {
				rankTop5Dpes = rankTop5Dpes.substring(0, rankTop5Dpes.length()-1);
			}
			params.put("rankTop5Dpes", rankTop5Dpes) ;
			if(cntindep>0) {
				mapTemp.put("CNTINDEPR", Arith.round(MonitorResultUtil.objectToDouble(mapTemp.get("CNTINDEPR")), 2));
		    	resultListSum.add(mapTemp);
		    	num++;
		    	// 清零
		    	cntindep = 0 ;
				cntindepR = 0.0 ;
		    } 
			String[] columnsT8 = {"RK","OPECODE","OPEDESC","OPELEVELCODE","DEP_NAME","CNTINDEP","CNTINDEPR(3)"} ;
			hosptable8=new ArrayList<List<String>>();
			hosptable8 = listMapToListArray(resultListSum,columnsT8) ;
			
			// 表格 9 各级手术作为主要手术出现频次最高的五位手术列表
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-2_mainOpeTop5","xinanyida_hosp_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			String[] columnsT9 = {"RK","OPELEVEL","OPECODE","OPEDESC","CNTOPE","CNTOPER(3)"} ;
			hosptable9=new ArrayList<List<String>>();
			hosptable9 = listMapToListArray(resultList,columnsT9) ;
			
			//3.3	日间手术分析
			sql = drgsIndexCalFacade.findSQLAnalysisreport("3-3_dayOpeSum","xinanyida_hosp_month",null,null);		
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			Map<String,Object> sumMap = new HashMap<>() ; 
			sumMap.putAll(resultList.get(0));
			params.put("33_opecntHosp", Arith.dataFormat(sumMap.get("OPECNT").toString(), "2")) ;
			params.put("33_dayOpecntHosp", Arith.dataFormat(sumMap.get("DAYOPECNT").toString(), "2")) ;
			params.put("33_dayOpecntHospR", sumMap.get("DAYOPECNTR")) ;
			params.put("33_dayOpecntHosp34", Arith.dataFormat(sumMap.get("DAYOPECNT34").toString(), "2")) ;
			params.put("33_dayOpecntHosp34R", sumMap.get("DAYOPECNT34R")) ;
			resultList = resultList.subList(1, resultList.size()) ;
			String[] columnsT10 = {"DEPNAME","OPECNT","DAYOPECNT","DAYOPECNTR(3)","DAYOPECNT34R(3)"} ;
			hosptable10=new ArrayList<List<String>>();
			hosptable10 = listMapToListArray(resultList,columnsT10) ;
 
			
		}
	}
	
	
	//加载第四章节信息
	public void loadARFourthSection(Map<String, Object> dto){
		/*//分组器版本号
	    String groupVersion=dto.get("groupVersion")==null?"--":dto.get("groupVersion").toString().trim();*/
		// 公共查询条件
		IndexCalDTO indexDto = new IndexCalDTO();
		indexDto.setDateFrom(dto.get("dateFrom")+"");
		indexDto.setDateTo(dto.get("dateTo")+"");
		indexDto.setMonitorType("dep");
		indexDto.setHospCode(dto.get("hospCode")+"");
		List<Map<String, Object>> resultList = new ArrayList<>() ;
		// 查询条件
		Map<String,Object> condition = new HashMap<>();
		condition.put("dateFrom", dto.get("dateFrom"));
		condition.put("dateTo", dto.get("dateTo"));
		condition.put("hospCode", dto.get("hospCode")==null?"":dto.get("hospCode")+""); //院区编码
		condition.put("ver_region", dto.get("ver_region"));
		condition.put("stdId", dto.get("stdId"));
		String sql = "" ;
		
		String depCode = MonitorResultUtil.object2String(dto.get("depCode")) ;
		if(StringUtils.hasLength(depCode)) {
			//科室
//			附表1  未入组病例明细
			sql = drgsIndexCalFacade.findSQLAnalysisreport("attachedTable1_noGroupDetail","xinanyida_hosp_month",null,null);
			//将科室信息加上
			condition.put("depCode", depCode);
			if(StringUtils.hasLength(depCode.toString().trim())) {
			sql = sql.replaceAll("1=1", " ipinfo.P00300001 is not null and ipinfo.P00300001=:depCode and 1=1 ");
			}
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			String[] columns1 = {"MR_NO","PNAME","OUTDATE","DEP_NAME","INDAYS","TOTALCOST","MDIAGNOSE","MOPERATION","DIC_DESC"} ;
			depattachedTable1=new ArrayList<List<String>>();
			depattachedTable1 = listMapToListArray(resultList,columns1) ;
			
			//附表2 科室DRG病组覆盖列表
			sql = "";
			sql = drgsIndexCalFacade.findSQLAnalysisreport("attachedTable2_depDRGCover","xinanyida_dep_month",null,null);
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			for(int i=0;i<=resultList.size()-1;i++){
				if(!(resultList.get(i)==null)){
					resultList.get(i).put("ROWNUMBER", i+1);
				}
			}
			String[] columns2 = {"ROWNUMBER","DRGCODE","DRGDESC","DRGCNT(2)","DRGWEIGHT(1)","ISINDEP"} ;
			depattachedTable2=new ArrayList<List<String>>();
			depattachedTable2 = listMapToListArray(resultList,columns2) ;
			
//			附表3  死亡病例明细
			sql = "" ;
			sql = drgsIndexCalFacade.findSQLAnalysisreport("attachedTable6_deathsDetail","xinanyida_hosp_month",null,null);
			//将科室信息加上
			if(StringUtils.hasLength(depCode.toString().trim())) {
			sql = sql.replaceAll("1=1", " ipinfo.P00300001 is not null and ipinfo.P00300001=:depCode and 1=1 ");
			}
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition);
			String[] columnsAttachedTable5 = {"MR_NO","PNAME","OUTDATE","DEP_NAME","INDAYS","TOTALCOST(3)","MDIAGNOSE","DRGCODE","DRG_DESC","AS_WEIGHT(1)","AS_AVG_DAYS(3)","AS_AVG_FEE(3)","DIC_DESC"} ;
			depattachedTable3=new ArrayList<List<String>>();
			depattachedTable3 = listMapToListArray(resultList,columnsAttachedTable5) ;
			
			//附表5 手术统计情况表
			sql="";
			sql = drgsIndexCalFacade.findSQLAnalysisreport("depAttachedTable5","xinanyida_dep_month",null,null);		
			//将科室信息加上
			if(StringUtils.hasLength(depCode.toString().trim())) {
			sql = sql.replaceAll("1=1", " ipinfo.P00300001 is not null and ipinfo.P00300001=:depCode and 1=1 ");
			}
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			String[] Columns = {"ROWNUMBER(2)","OPERDESC","OPERCNT(2)","OPERRADIO(1)","OPERLEVEL"} ;
			depattachedTable5=new ArrayList<List<String>>();
			depattachedTable5 = listMapToListArray(resultList,Columns) ;
			
		}else{
//			附表1  未入组病例明细
			sql = drgsIndexCalFacade.findSQLAnalysisreport("attachedTable1_noGroupDetail","xinanyida_hosp_month",null,null);
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			resultList = sortListMap(resultList, "DIC_DESC", "desc") ;
			String[] columns1 = {"MR_NO","PNAME","OUTDATE","DEP_NAME","INDAYS","TOTALCOST","MDIAGNOSE","MOPERATION","DIC_DESC"} ;
			hospattachedTable1=new ArrayList<List<String>>();
			hospattachedTable1 = listMapToListArray(resultList,columns1) ;
			
//			附表2  MDC专业效率环比变化分析
			indexDto.setQuotaCode("InCaseCnt,TimeEff,FeeEff");
			indexDto.setIsGetCc("1");
			indexDto.setMonitorType("mdc");
			indexDto.setCompareType("year");
			resultList = drgsIndexCalFacade.indexCal(indexDto); 
			Map<String, String> quotaMap = new HashMap<>() ;
			quotaMap.put("xDirection", "-1");
			quotaMap.put("yDirection", "-1");
			quotaMap.put("quotaCodeX", "TimeEff");
			quotaMap.put("quotaCodeY", "FeeEff");
			quotaMap.put("compareAttribute", "len");
			resultList = orderScatterData(quotaMap, resultList, "cc") ;
			for(Map<String,Object> map : resultList) {
				double d = MonitorResultUtil.objectToDouble(map.get("len")) ;
				if(d>0) {
					map.put("trend", "变好") ;
				} else if(d<0) {
					map.put("len", (-d)+"") ;
					map.put("trend", "变差") ;
				} else {
					map.put("trend", "不变") ;
				}
			}
			Collections.sort(resultList, new Comparator<Map<String, Object>>() {
			 	@Override
			    public int compare(Map<String, Object> m1, Map<String, Object> m2) {
			 		String s1 = MonitorResultUtil.object2String(m1.get("trend"));
			 		String s2 = MonitorResultUtil.object2String(m2.get("trend"));
			 		if(s1.compareTo(s2)==0) {
		 			    Double v1 = MonitorResultUtil.objectToDouble(m1.get("len")) ;
				        Double v2 = MonitorResultUtil.objectToDouble(m2.get("len")) ;
				        return v2.compareTo(v1);
			 		} else {
			 			return s1.compareTo(s2);
			 		}
			    }
			});
			
			String[] columns = {"trend","len(3)","ccode","ddesc","InCaseCnt(2)","TimeEff(1)","FeeEff(1)","TimeEffcc(1)","FeeEffcc(1)"} ;
			hospattachedTable2=new ArrayList<List<String>>();
			hospattachedTable2 = listMapToListArray(resultList, columns);
			
			
//			附表3  科室效率环比变化分析
			indexDto.setMonitorType("dep");
			resultList = drgsIndexCalFacade.indexCal(indexDto); 
			Map<String, String> quotaMapDep = new HashMap<>() ;
			quotaMapDep.put("xDirection", "-1");
			quotaMapDep.put("yDirection", "-1");
			quotaMapDep.put("quotaCodeX", "TimeEff");
			quotaMapDep.put("quotaCodeY", "FeeEff");
			quotaMapDep.put("compareAttribute", "len");
			resultList = orderScatterData(quotaMapDep, resultList, "cc") ;
			for(Map<String,Object> map : resultList) {
				double d = MonitorResultUtil.objectToDouble(map.get("len")) ;
				if(d>0) {
					map.put("trend", "变好") ;
				} else if(d<0) {
					map.put("len", (-d)+"") ;
					map.put("trend", "变差") ;
				} else {
					map.put("trend", "不变") ;
				}
			}
			Collections.sort(resultList, new Comparator<Map<String, Object>>() {
			 	@Override
			    public int compare(Map<String, Object> m1, Map<String, Object> m2) {
			 		String s1 = MonitorResultUtil.object2String(m1.get("trend"));
			 		String s2 = MonitorResultUtil.object2String(m2.get("trend"));
			 		if(s1.compareTo(s2)==0) {
		 			    Double v1 = MonitorResultUtil.objectToDouble(m1.get("len")) ;
				        Double v2 = MonitorResultUtil.objectToDouble(m2.get("len")) ;
				        return v2.compareTo(v1);
			 		} else {
			 			return s1.compareTo(s2);
			 		}
			    }
			});
			String[] columnsDep = {"trend","len(3)","ddesc","InCaseCnt(2)","TimeEff(1)","FeeEff(1)","TimeEffcc(1)","FeeEffcc(1)"} ;
			hospattachedTable3=new ArrayList<List<String>>();
			hospattachedTable3 = listMapToListArray(resultList, columnsDep);
//			
//			附表4  全院及各MDC专业DRG病组覆盖及医疗服务综合能力情况表
			indexDto.setQuotaCode("InCaseCnt,DrgCountInMdc,DrgsCoverageRation,CMI,DRGCount,TotalWeight,TimeEff,FeeEff,Risk1Ratio,Risk2Ratio");
			indexDto.setIsGetCc("0");
			indexDto.setMonitorType("mdc");
			resultList = drgsIndexCalFacade.indexCal(indexDto);
			resultList = sortListMap(resultList, "InCaseCnt", "desc") ;	
			int num = 1 ;
			for(Map<String,Object> map:resultList) {
				map.put("num",num++) ;
			}	
			indexDto.setMonitorType("hosp");
			List<Map<String, Object>>  resultHospList = drgsIndexCalFacade.indexCal(indexDto);
			if(resultHospList!=null && resultHospList.size()>0) {
				resultHospList.get(0).put("ccode", "全院") ;
				resultHospList.get(0).put("ddesc", " ") ;
				resultList.add(0,resultHospList.get(0)) ;
			}
			String[] attachedTable4columns = {"num","ccode","ddesc","InCaseCnt(2)","DrgCountInMdc(2)","DrgsCoverageRation(1)","CMI(1)","DRGCount(2)","TotalWeight(3)","TimeEff(1)","FeeEff(1)","Risk1Ratio(1)","Risk2Ratio(1)"} ;
			hospattachedTable4=new ArrayList<List<String>>();
			hospattachedTable4 = listMapToListArray(resultList, attachedTable4columns) ;
			
//			
//			附表5  全院及各科室医疗服务综合能力情况表
			indexDto.setQuotaCode("InCaseCnt,CMI,DRGCount,TotalWeight,TimeEff,FeeEff,Risk1Ratio,Risk2Ratio");
			indexDto.setMonitorType("dep");
			resultList = drgsIndexCalFacade.indexCal(indexDto);
			resultList = sortListMap(resultList, "InCaseCnt", "desc") ;		
			num = 1 ;
			for(Map<String,Object> map:resultList) {
				map.put("num",num++) ;
			}	
			indexDto.setMonitorType("hosp");
			List<Map<String, Object>>  resultHospDepList = drgsIndexCalFacade.indexCal(indexDto);
			if(resultHospDepList!=null && resultHospDepList.size()>0) {
				resultHospDepList.get(0).put("ddesc", "全院") ;
				resultList.add(0,resultHospDepList.get(0)) ;
			}
			String[] attachedTable5columns = {"num","ddesc","InCaseCnt(2)","CMI(1)","DRGCount(2)","TotalWeight(3)","TimeEff(1)","FeeEff(1)","Risk1Ratio(1)","Risk2Ratio(1)"} ;
			hospattachedTable5=new ArrayList<List<String>>();
			hospattachedTable5 = listMapToListArray(resultList, attachedTable5columns) ;
//			
		//	附表7  科室死亡病例分布情况
			sql = drgsIndexCalFacade.findSQLAnalysisreport("depDistributionOfDeaths","xinanyida_hosp_month",null,null);
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			Map<Object,Map<String,Object>> table5Map = new LinkedHashMap<>() ;
			for(Map<String,Object> map : resultList) {
				Object key = MonitorResultUtil.object2String(map.get("CCODE"))+"-"+
							 MonitorResultUtil.object2String(map.get("RISKLEVEL")) ;
				map.put("DEADRATIO", Arith.dataFormat(MonitorResultUtil.object2String(map.get("DEADRATIO")) , "1"));
				table5Map.put(key,map) ;
			}
			// 同期
			condition.put("dateFrom", dto.get("dateFromY")) ;
			condition.put("dateTo", dto.get("dateToY")) ;
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			for(Map<String,Object> map : resultList) {
				Object key = MonitorResultUtil.object2String(map.get("CCODE"))+"-"+
							 MonitorResultUtil.object2String(map.get("RISKLEVEL")) ;
				if(table5Map.get(key)!=null) {
					table5Map.get(key).put("DEADRATIOY",map.get("DEADRATIO")) ;
				}
			}
			// 上期
			condition.put("dateFrom", dto.get("dateFromQ")) ;
			condition.put("dateTo", dto.get("dateToQ")) ;
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			for(Map<String,Object> map : resultList) {
				Object key = MonitorResultUtil.object2String(map.get("CCODE"))+"-"+
							 MonitorResultUtil.object2String(map.get("RISKLEVEL")) ;
				if(table5Map.get(key)!=null) {
					table5Map.get(key).put("DEADRATIOQ",map.get("DEADRATIO")) ;
				}
			}
			resultList = mapToList(table5Map) ;
			Map<String,Object> deadCntMap = new HashMap<>() ;
			int deadCaseCnt = 0 ;
			int risk1DeadCaseCnt= 0 ;
			
			
			
			for(Map<String,Object> map : resultList) {
				double deadRatioYoY =  MonitorResultUtil.calculator("-", map.get("DEADRATIO"), map.get("DEADRATIOY")) ;
				double deadRatioQoQ = MonitorResultUtil.calculator("-", map.get("DEADRATIO"), map.get("DEADRATIOQ")) ;
				if(deadRatioYoY>0) {
					map.put("DEADRATIOYoY", "+"+ Arith.dataFormat(deadRatioYoY+"", "1"));
				} else if(deadRatioYoY<0) {
					map.put("DEADRATIOYoY", "-"+ Arith.dataFormat(Math.abs(deadRatioYoY)+"", "1"));
				} else {
					map.put("DEADRATIOYoY", Arith.dataFormat(deadRatioYoY+"", "1"));
				}
				if(deadRatioQoQ>0) {
					map.put("DEADRATIOQoQ", "+"+ Arith.dataFormat(deadRatioQoQ+"", "1"));
				} else if(deadRatioQoQ<0) {
					map.put("DEADRATIOQoQ", "-"+ Arith.dataFormat(Math.abs(deadRatioQoQ)+"", "1"));
				} else {
					map.put("DEADRATIOQoQ", Arith.dataFormat(deadRatioQoQ+"", "1"));
				}
				// 统计死亡病例数和低风险等级死亡病例数
				if("1".equals(MonitorResultUtil.object2String(map.get("RISKLEVEL")))) {
					risk1DeadCaseCnt = (int) (risk1DeadCaseCnt + MonitorResultUtil.objectToDouble(map.get("DEADCASECNT"))) ;
				}
				deadCntMap.put(MonitorResultUtil.object2String(map.get("CCODE")), map.get("DEADCASECNTDEP")) ;
			}
			Iterator<Entry<String, Object>> deadCntIt= deadCntMap.entrySet().iterator() ;
			while(deadCntIt.hasNext()) {
				Entry<String, Object> entry = deadCntIt.next() ;
				deadCaseCnt+= MonitorResultUtil.objectToDouble(entry.getValue()) ;
			}
			params.put("234-deadCaseCnt", deadCaseCnt);
			params.put("234-risk1DeadCaseCnt", risk1DeadCaseCnt);
			String[] columnsAttachedTable7 = {"DDESC","DEADCASECNTDEP(2)","RISKLEVELDESC","INCASECNT","DEADCASECNT","DEADRATIO","DEADRATIOYoY","DEADRATIOQoQ"} ;
			hospattachedTable7=new ArrayList<List<String>>();
			hospattachedTable7 = listMapToListArray(resultList,columnsAttachedTable7) ;
			
	
//			附表8  入组死亡病例明细
			condition.put("dateFrom", dto.get("dateFrom"));
			condition.put("dateTo", dto.get("dateTo"));
			sql = drgsIndexCalFacade.findSQLAnalysisreport("attachedTable6_deathsDetail","xinanyida_hosp_month",null,null);
			resultList =  monthAnalysisReportApplication.executeQueryForList(sql, condition) ;
			resultList = sortListMap(resultList, "DEP_NAME", "desc") ;		
			String[] columnsAttachedTable8 = {"MR_NO","PNAME","OUTDATE","DEP_NAME","INDAYS","TOTALCOST(3)","MDIAGNOSE","DRGCODE","DRG_DESC","AS_WEIGHT(1)","AS_AVG_DAYS(3)","AS_AVG_FEE(3)","DIC_DESC"} ;
			hospattachedTable8=new ArrayList<List<String>>();
			hospattachedTable8 = listMapToListArray(resultList,columnsAttachedTable8) ;
		}

	}

		/**
		 * @methodname :imputedRatio
		 * @Description : 计算百分比
		 * @author:LiuHongjun
		 * @return Double
		 * @date :2016年9月10日
		 */
		public Double imputedRatio(Double a, Double b) {
			return Arith.mul(Arith.div(a, b, 4), 100);
		}
		//生成文档
		@Override
		public Map<String, Object> createDRGsReport() throws IOException {
			
			//1构建手术级别分布
			Map<String,Object> monthHospPicone = new HashMap<String, Object>();  
			monthHospPicone.put("width", 560);
			monthHospPicone.put("height", 260);
			monthHospPicone.put("type", "jpg");
			monthHospPicone.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPicone.jpg"), true));
		    params.put("monthHospPicone",monthHospPicone);
		    
			//2构建手术级别分布
			Map<String,Object> monthHospPictwo = new HashMap<String, Object>();  
			monthHospPictwo.put("width", 560);
			monthHospPictwo.put("height", 260);
			monthHospPictwo.put("type", "jpg");
			monthHospPictwo.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPictwo.jpg"), true));
		    params.put("monthHospPictwo",monthHospPictwo);
		    
			//3构建全院病例难度分布图
			Map<String,Object> monthHospPicthree = new HashMap<String, Object>();  
			monthHospPicthree.put("width", 560);
			monthHospPicthree.put("height", 260);
			monthHospPicthree.put("type", "jpg");
			monthHospPicthree.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPicthree.jpg"), true));
		    params.put("monthHospPicthree",monthHospPicthree);
		    		    
		    if("".equals(reportType)){    	
		    	//以下图是全院特有的
		    	
				//4MDC专业病组覆盖率分布图
				Map<String,Object> monthHospPicfour = new HashMap<String, Object>();  
				monthHospPicfour.put("width", 560);
				monthHospPicfour.put("height", 260);
				monthHospPicfour.put("type", "jpg");
				monthHospPicfour.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPicfour.jpg"), true));
			    params.put("monthHospPicfour",monthHospPicfour);
		    
				//8构建MDC专业时间消耗指数和费用消耗指数象限分布图（环比正向变好）
				Map<String,Object> monthHospPiceight = new HashMap<String, Object>();  
				monthHospPiceight.put("width", 560);
				monthHospPiceight.put("height", 260);
				monthHospPiceight.put("type", "jpg");
				monthHospPiceight.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPiceight.jpg"), true));
			    params.put("monthHospPiceight",monthHospPiceight);
			    
				//9构建MDC专业时间消耗指数和费用消耗指数象限分布图（环比负向变差）
				Map<String,Object> monthHospPicnine = new HashMap<String, Object>();  
				monthHospPicnine.put("width", 560);
				monthHospPicnine.put("height", 260);
				monthHospPicnine.put("type", "jpg");
				monthHospPicnine.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPicnine.jpg"), true));
			    params.put("monthHospPicnine",monthHospPicnine);
			    
				//10构建科室总权重及其出院病例数全院占比分布图（总权重前10）
				Map<String,Object> monthHospPicten = new HashMap<String, Object>();  
				monthHospPicten.put("width", 560);
				monthHospPicten.put("height", 260);
				monthHospPicten.put("type", "jpg");
				monthHospPicten.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPicten.jpg"), true));
			    params.put("monthHospPicten",monthHospPicten);

				//11构建科室时间消耗指数和费用消耗指数象限分布图（环比正向变好）
				Map<String,Object> monthHospPiceleven = new HashMap<String, Object>();  
				monthHospPiceleven.put("width", 560);
				monthHospPiceleven.put("height", 260);
				monthHospPiceleven.put("type", "jpg");
				monthHospPiceleven.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPiceleven.jpg"), true));
			    params.put("monthHospPiceleven",monthHospPiceleven);
			    
				//12构建科室时间消耗指数和费用消耗指数象限分布图（环比负向变差）
				Map<String,Object> monthHospPictwelve = new HashMap<String, Object>();  
				monthHospPictwelve.put("width", 560);
				monthHospPictwelve.put("height", 260);
				monthHospPictwelve.put("type", "jpg");
				monthHospPictwelve.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPictwelve.jpg"), true));
			    params.put("monthHospPictwelve",monthHospPictwelve);
			    
			    //1new手术与非手术占比图
				Map<String,Object> monthHospPiconenew = new HashMap<String, Object>();  
				monthHospPiconenew.put("width", 560);
				monthHospPiconenew.put("height", 260);
				monthHospPiconenew.put("type", "jpg");
				monthHospPiconenew.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPiconenew.jpg"), true));
			    params.put("monthHospPiconenew",monthHospPiconenew);
			    
			    //2new各级手术分布占比图
				Map<String,Object> monthHospPictwonew = new HashMap<String, Object>();  
				monthHospPictwonew.put("width", 560);
				monthHospPictwonew.put("height", 260);
				monthHospPictwonew.put("type", "jpg");
				monthHospPictwonew.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPictwonew.jpg"), true));
			    params.put("monthHospPictwonew",monthHospPictwonew);
		    }else{
		    	//以下图是科室特有的
		    	
			    //14构建科室DRG病组有效占比变化趋势图
				Map<String,Object> monthHospPicfourteen = new HashMap<String, Object>();  
				monthHospPicfourteen.put("width", 560);
				monthHospPicfourteen.put("height", 260);
				monthHospPicfourteen.put("type", "jpg");
				monthHospPicfourteen.put("content", WordUtil.inputStream2ByteArray(new FileInputStream(picRootio+"monthHospPicfourteen.jpg"), true));
			    params.put("monthHospPicfourteen",monthHospPicfourteen);
		    	
		    }

		    
			Map<String,Object> mapAR=new HashMap<String,Object>();
			  try{
				  CustomXWPFDocument doc =new CustomXWPFDocument();
				  String analysisReportRoot="";
				  if("".equals(reportType)){
					  analysisReportRoot="hospMonthReportnew.docx"; //全院分析报告
				  }else{
					  if("1".equals(depCodeQuFen)){
						  analysisReportRoot="depNeiMonthReportnew.docx"; //科室内科
					  }else{
						  analysisReportRoot="depWaiMonthReportnew.docx"; //科室外科
					  }
				  }
				  doc = WordUtil.generateWord(params, wordRootio+analysisReportRoot);
				  WordUtil.insertValueToTable(doc, hosptable1, 2, true);
				  if("".equals(reportType)){    
					  WordUtil.insertValueToTable(doc, hosptable4, 3, true);
					  WordUtil.insertValueToTable(doc, hosptable5, 4, true);
					  WordUtil.insertValueToTable(doc, hosptable6, 5, true);
					  WordUtil.insertValueToTable(doc, hosptable7, 6, true);
					  WordUtil.insertValueToTable(doc, hosptable8, 7, true);
					  WordUtil.insertValueToTable(doc, hosptable9, 8, true);
					  WordUtil.insertValueToTable(doc, hosptable10, 9, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable1, 10, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable2, 11, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable3, 12, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable4, 13, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable5, 14, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable6, 15, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable7, 16, true);
					  WordUtil.insertValueToTable(doc, hospattachedTable8, 17, true);
				  }else{
					  WordUtil.insertValueToTable(doc, deptable3, 3, true);
					  WordUtil.insertValueToTable(doc, deptable4, 4, true);
					  WordUtil.insertValueToTable(doc, deptable5, 5, true);
					  WordUtil.insertValueToTable(doc, deptable6, 6, true);
					  WordUtil.insertValueToTable(doc, deptable7, 7, true);
					  WordUtil.insertValueToTable(doc, deptable8, 12, true);
					  WordUtil.insertValueToTable(doc, deptable9, 13, true);
					  WordUtil.insertValueToTable(doc, depattachedTable1, 9, true);
					  WordUtil.insertValueToTable(doc, depattachedTable2, 10, true);
					  WordUtil.insertValueToTable(doc, depattachedTable3, 11, true);
					  WordUtil.insertValueToTable(doc, depattachedTable5, 8, true);
				  }

				  reportNo = System.currentTimeMillis(); //生成文档结束时间
				  File folder = new File(writeRootio);
				  if (!folder.exists()) {
						folder.mkdirs();
					}
				 String outputFile = folder.getPath() + File.separator + reportNo + ".docx";
				 FileOutputStream fopts = new FileOutputStream(outputFile);
				 doc.write(fopts);
				 fopts.close();
				 System.err.println(" \n 文档生成成功 path=\n" + outputFile);
				 System.err.println("生成文档耗时time=" + (System.currentTimeMillis() - start) / 1000);
				 mapAR.put("patch", "tmp/"+reportNo+".docx");
				 mapAR.put("hospname", params.get("hospName")+"");
				 mapAR.put("depName", params.get("depName")+"");
				 mapAR.put("reportDate", params.get("reportDate")+"");
				 
				 return mapAR;
              } catch (Exception e) {
				  e.printStackTrace();
			  }
			  return mapAR;
		}

		/**
		 * 
		* @ClassName: TestRunnable 
		* @Description: 线程 第一章节
		* @author shaozhiyuan
		* @date 2017年11月29日 下午3:43:02 
		*
		 */
	private	class AnalysisReportRunnableA implements Runnable {
		private Map<String, Object> dto=new HashMap<String, Object>();
		AnalysisReportRunnableA(Map<String, Object> dto){
			this.dto = dto ;
		}
	    public void run() { 
			try {
				loadARFirstSection(dto);   
			} catch (Exception e) { 
			    e.printStackTrace(); 
			} 
	    }
	}
	
	private	class AnalysisReportRunnableB implements Runnable {
		private Map<String, Object> dto=new HashMap<String, Object>();
		AnalysisReportRunnableB(Map<String, Object> dto){
			this.dto = dto ;
		}
	    public void run() { 
			try {
				loadARTwoSection(dto);   
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
	    }
	}
	
	private	class AnalysisReportRunnableC implements Runnable {
		private Map<String, Object> dto=new HashMap<String, Object>();
		AnalysisReportRunnableC(Map<String, Object> dto){
			this.dto = dto ;
		}
		public void run() { 
			try {
				loadARThirdSection(dto);   
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		}
	}
	
	private	class AnalysisReportRunnableD implements Runnable {
		private Map<String, Object> dto=new HashMap<String, Object>();
		AnalysisReportRunnableD(Map<String, Object> dto){
			this.dto = dto ;
		}
		public void run() { 
			try {
				loadARFourthSection(dto);   
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		}
	}
	
	
	 /**
	  *  散点排序
	  *  orderScatterData.  
	  *  @Description：
	  *  @Author ChenHanlin
	  *  @param quotaMap
	  *  @param list
	  *  @param suffix
	  *  @return 
	  *  @Date:2018年6月21日下午4:25:22
	  */
	 public List<Map<String,Object>> orderScatterData(Map<String,String> quotaMap,List<Map<String,Object>> list,String suffix) {
		int xDirection = quotaMap.get("xDirection")==null?1:Integer.parseInt(quotaMap.get("xDirection"));
		int yDirection = quotaMap.get("yDirection")==null?1:Integer.parseInt(quotaMap.get("yDirection"));
		List<Map<String,Object>> resultList = new ArrayList<>() ;
		String quotaCodeX = quotaMap.get("quotaCodeX") ;
		String quotaCodeY = quotaMap.get("quotaCodeY") ;
		final String compareAttribute = quotaMap.get("compareAttribute") ;
		for(Map<String,Object> map : list) {
			double x = 0.0 ;
			double y = 0.0 ;
			if(map.get(quotaCodeX+suffix) == null || map.get(quotaCodeY+suffix)==null ) {
				continue ;
			}
			x= MonitorResultUtil.objectToDouble(map.get(quotaCodeX))- MonitorResultUtil.objectToDouble(map.get(quotaCodeX+suffix));
			y= MonitorResultUtil.objectToDouble(map.get(quotaCodeY))- MonitorResultUtil.objectToDouble(map.get(quotaCodeY+suffix));
			double result = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
			if(result==Double.NEGATIVE_INFINITY || result==-Double.NEGATIVE_INFINITY ){
				map.put(compareAttribute, 0);
			}else if(map.get(quotaCodeX+suffix) == null || map.get(quotaCodeY+suffix)==null){
				map.put(compareAttribute, 0);
			}else{
				if(xDirection*x>0&&yDirection*y>0) {
					//变好
					map.put(compareAttribute, result);
				} else {
					//变差
					map.put(compareAttribute, -result);
				}
			}
			resultList.add(map) ;
		}
		//  降序排列
//		Collections.sort(resultList, new Comparator<Map<String, Object>>() {
//		 	@Override
//		    public int compare(Map<String, Object> m1, Map<String, Object> m2) {
//		        Double v1 = MonitorResultUtil.objectToDouble(m1.get(compareAttribute));
//		        Double v2 = MonitorResultUtil.objectToDouble(m2.get(compareAttribute));
//		        if (v2 != null) { 
//		            return v2.compareTo(v1);
//		        }
//		        return 0;
//		    }
//		});
//		int ranking = 1;//排名 
//		for(Map<String,Object> map : resultList) {
//			map.put("ranking", ranking++) ;
//		}
		return resultList;
	 }
    
	 /**
	  *  List<Map<String, Object>> 转 List<List<String>>
	  *  listMapToListArray.  
	  *  @Description：
	  *  @Author ChenHanlin
	  *  @param list
	  *  @param columns
	  *  @return 
	  *  @Date:2018年6月22日下午2:10:49
	  */
	 public List<List<String>>  listMapToListArray(List<Map<String,Object>> list,String[] columns) {
		 List<List<String>> result = new ArrayList<>() ;
		 // 匹配括号里的内容
		 String regex = "\\(.*\\)";
		 if(list!=null && list.size()>0) {
			 for(Map<String,Object> map : list) {
				 List<String> tmpList = new ArrayList<>() ;
				 for(String str : columns) {
					 String column = str ;
					 String type = "" ;
					 // 匹配格式化类型
					 Pattern pattern = Pattern.compile(regex);  
					 Matcher matcher = pattern.matcher(column);  
					 // 匹配格式化设置
					 if(matcher.find()){
						 type = matcher.group(0).replace("(", "").replace(")", ""); 
						 column = column.replaceAll(regex, "");
					 }
					 if(Arith.isNumeric(type)) {
						 double numm = MonitorResultUtil.objectToDouble(map.get(column)) ;
						 if(numm<0) {
							 map.put(column, "-"+ Arith.dataFormat(Math.abs(numm)+"", type)) ;
						 } else {
							 map.put(column, Arith.dataFormat(numm+"", type)) ;
						 }
					 } else {
						 if(map.get(column) == null) {
							 map.put(column, "-") ;
						 }
					 }
					 tmpList.add(MonitorResultUtil.object2String(map.get(column))) ;
				 }
				 result.add(tmpList) ;
			 }
		 } else {
			 List<String> tmpList = new ArrayList<>() ;
			 for(String str : columns) {
				 tmpList.add("-") ;
			 }
			 result.add(tmpList) ;
		 }
		 return result;
	 }
	 
	 /**
	  *  map -> list
	  *  mapToList.  
	  *  @Description：
	  *  @Author ChenHanlin
	  *  @param map
	  *  @return 
	  *  @Date:2018年6月24日下午1:33:56
	  */
 	public List<Map<String,Object>> mapToList(Map<Object,Map<String,Object>> map) {
		List<Map<String,Object>> list = new ArrayList<>() ;
		if(map == null) {
			return list ;
		}
		Iterator<Entry<Object, Map<String, Object>>>  it = map.entrySet().iterator();  
		while (it.hasNext()) {  
			Entry<Object, Map<String, Object>> entry = it.next();  
			Map<String, Object> value = entry.getValue();  
			list.add(value); 
		}  
		return list ;
	 }
	
 	/**
 	 *  list->Map
 	 *  listToMap.  
 	 *  @Description：
 	 *  @Author ChenHanlin
 	 *  @param list
 	 *  @param filed
 	 *  @return 
 	 *  @Date:2018年6月24日下午1:38:19
 	 */
	public Map<Object,Map<String,Object>> listToMap(List<Map<String,Object>> list, String filed) {
		Map<Object,Map<String,Object>> mapBase = new HashMap<>() ;
		if(list == null) {
			return mapBase ;
		}
		// 遍历新List将结果放至原map中
		for(Map<String,Object> map : list) {
			if(map.get(filed) != null){
				mapBase.put(map.get(filed)+"", map) ;
			}
		}
		return mapBase;
	}
	
	/**
	 *  
	 *  sortToMap.  
	 *  @Description：
	 *  @Author ChenHanlin
	 *  @param mapList
	 *  @param sort
	 *  @param order
	 *  @return 
	 *  @Date:2018年6月23日下午6:41:10
	 */
	public List<Map<String, Object>> sortListMap(List<Map<String, Object>> mapListP, final String sort, final String order) {
		   List<Map<String, Object>> mapList = (List<Map<String, Object>>) DrgsIndex.copyPropertiesObj(mapListP) ;
		   Collections.sort(mapList, new Comparator<Map<String, Object>>() {
			   public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				   String map1values = MonitorResultUtil.object2String(o1.get(sort));
	               String map2values = MonitorResultUtil.object2String(o2.get(sort));
				   if(Arith.isNumeric(map1values) && Arith.isNumeric(map2values)) {
	            	   Double map1value = MonitorResultUtil.objectToDouble(o1.get(sort));
		               Double map2value = MonitorResultUtil.objectToDouble(o2.get(sort));
		               if ("DESC".equals(order.toUpperCase())) {
		                   return map2value.compareTo(map1value);
		               } else {
		                   return map1value.compareTo(map2value);
		               }
	               } else {
	            	   if ("DESC".equals(order.toUpperCase())) {
		                   return map2values.compareTo(map1values);
		               } else {
		                   return map1values.compareTo(map2values);
		               }
	               }
	           }
		   });
		   return mapList;
		}
	
}

